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

Sort TDs with select tags #134

Open
cleveralmeida opened this issue Dec 16, 2014 · 6 comments
Open

Sort TDs with select tags #134

cleveralmeida opened this issue Dec 16, 2014 · 6 comments

Comments

@cleveralmeida
Copy link

This plugin is very good but I have an issue when a TD has select tag. In this case, it doesn't work.

sort
sort2

@joequery
Copy link
Owner

You can attach an event to the select boxes within the table to update their parent td's sort-value jquery data attribute to be the value you wish to have.

@joequery
Copy link
Owner

I'll try and cook up a demo if I can find time, but I'm a bit busy unfortunately.

@ljpaul
Copy link

ljpaul commented Nov 1, 2015

I was actually just struggling with this. I am going to have to do what you suggest, so I can post my solution. It would be awesome in the future if we could add a table-sort-value attribute to the option tags and it could sort on the selected option. I tried to cook up a custom type, but was unsuccessful.

@joequery
Copy link
Owner

joequery commented Nov 1, 2015

@ljpaul You can hook into the beforetablesort event and manually set the data-sort-value of the cells which contain select boxes to be the value of the select box.

@FredZCalgary
Copy link

This is an old comment and I'm new to this nice little sorter and GitHub, so forgive me if this is not the right way to deal with this.

I had the same problem for a table containing s which contained a mixture of selects, inputs, textareas, nothing and text.

I added and changed a bit of code at the table_structure.sort function call at about line 208 as follows:

 var $CellContentE1=$(e1.$tr[0].cells[th_index]).find('input, select, textarea');
  $CellContentE1=$CellContentE1.length==0 ?  e1.columns[th_index] : $CellContentE1.val();
  var $CellContentE2=$(e2.$tr[0].cells[th_index]).find('input, select, textarea');
  $CellContentE2=$CellContentE2.length==0 ?  e2.columns[th_index] : $CellContentE2.val();
  //var diff = sort_info.compare_fn(e1.columns[th_index], e2.columns[th_index]);
  var diff = sort_info.compare_fn($CellContentE1,$CellContentE2); 

Seems to work well, hope it helps.

@joequery
Copy link
Owner

Thanks for noting your solution here @FredZCalgary !

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

No branches or pull requests

4 participants