Tablesorter - filter functions on empty cells

五迷三道 提交于 2019-12-11 05:37:54

问题


I'm using the tablesorter 2.7.9 (Mottie's fork) with the filter functions widget and I'd like to have the built-in select droplist be able to select empty cell values as a filter option. Does anyone know an easy way to do this aside from putting fake values in all the empty cells? Already my filter droplist contains 2 blank options: one for deselecting the filter and one to match the data value from my table, but of course setting it to this just deselects the filter.


回答1:


Sadly there isn't an easy way to select empty cells with the way the filter widget is written. The main problem is how do we differentiate between clearing the filter and searching for empty table cells?

I could add some way to specifically find empty table cells, or as you said add "fake" values into the empty table cells - one way is to add <span style="display:none">{empty}</span> inside of empty cells. Then the select dropdown would include an {empty} entry so users know what they are selecting (demo).

Would that work for you?




回答2:


You can search for an empty string using regex

var filters = [],
col = <insertColumnNumberHere>, // the column number to perform the search on
txt = "/^$/"; // ^$ = empty string
filters[col] = txt;
$.tablesorter.setFilters($('table'), filters, true);

With the knowledge of the empty string regex you should be able to create a droplist where one of the blank options has a value of "/^$/".



来源:https://stackoverflow.com/questions/14990971/tablesorter-filter-functions-on-empty-cells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!