Stupid-Table-Plugin icon indicating copy to clipboard operation
Stupid-Table-Plugin copied to clipboard

Sort TDs with select tags

Open cleveralmeida opened this issue 9 years ago • 6 comments

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

cleveralmeida avatar Dec 16 '14 01:12 cleveralmeida

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 avatar Dec 16 '14 06:12 joequery

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

joequery avatar Dec 16 '14 06:12 joequery

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.

ljpaul avatar Nov 01 '15 20:11 ljpaul

@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.

joequery avatar Nov 01 '15 21:11 joequery

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.

FredZCalgary avatar Apr 23 '18 15:04 FredZCalgary

Thanks for noting your solution here @FredZCalgary !

joequery avatar Apr 23 '18 15:04 joequery