Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added helper function to fix table widths when dragging #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nicholasjackson
Copy link

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 <[email protected]>
@BobbyRichard
Copy link

This is a great addition. Please accept it!

@rniemeyer
Copy link
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
Copy link
Contributor

JD-Robbs commented Mar 1, 2016

@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