Stupid-Table-Plugin
Stupid-Table-Plugin copied to clipboard
Sort TDs with select tags
This plugin is very good but I have an issue when a TD has select tag. In this case, it doesn't work.
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.
I'll try and cook up a demo if I can find time, but I'm a bit busy unfortunately.
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 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.
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
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.
Thanks for noting your solution here @FredZCalgary !