Skip to content

Added helper function to fix table widths when dragging#46

Open
nicholasjackson wants to merge 1 commit into
rniemeyer:masterfrom
nicholasjackson:master
Open

Added helper function to fix table widths when dragging#46
nicholasjackson wants to merge 1 commit into
rniemeyer:masterfrom
nicholasjackson:master

Conversation

@nicholasjackson

Copy link
Copy Markdown

When dragging table rows the widths of the cells compress to content and loose their set values. I have added a helper function to the sortable options to fix the widths.

sortable.options.helper = function(e, ui) {
  ui.children().each(function() {
     $(this).width($(this).width());
  });
  return ui;
};

Added helper function to options to fix table widths when dragging.

Signed-off-by: Nicholas Jackson <nic@thatlondon.com>
@BobbyRichard

Copy link
Copy Markdown

This is a great addition. Please accept it!

@rniemeyer

Copy link
Copy Markdown
Owner

It would be nice to restrict this in some way to tables, so it doesn't need to run for every sortable all of the time.

@JD-Robbs

JD-Robbs commented Mar 1, 2016

Copy link
Copy Markdown
Contributor

@nicholasjackson Would you mind me giving it a go and adapting your PR to be restricted to tr elements? Unless, of course, you'd like to re-submit yourself. Just asking since I'd love to see this supported.

I suppose it's simply a matter of:

sortable.options.helper = function(e, ui) { if (ui.is('tr')) { ui.children('td, th').each(function() { $(this).width($(this).width()); }); } return ui; }; Not sure if the `if (ui.is('tr'))` check is necessary - just thought it may be faster than searching the children for `td`/`th` every time.

Edit - removed the element query since, rather obviously, nothing else could/should be inside a tr:

sortable.options.helper = function(e, ui) {
  if (ui.is('tr')) {
    ui.children().each(function() {
      $(this).width($(this).width());
    });
  }
  return ui;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants