Помощь с фильтром в таблице
Ребят, уж не один день разбирался... подскажите, пожалуйста, кто может... Есть следующая функция, осуществляющая фильтрацию строк по данным конкретного столбца. Сама функция:
table.filter = function(o,filters,args) { var cell; args = args || {}; var t = this.resolve(o,args); var tdata = this.tabledata[t.id]; // If new filters were passed in, apply them to the table's list of filters if (!filters) { // If a null or blank value was sent in for 'filters' then that means reset the table to no filters tdata.filters = null; } else { // Allow for passing a select list in as the filter, since this is common design if (filters.nodeName=="SELECT" && filters.type=="select-one" && filters.selectedIndex>-1) { filters={ 'filter':filters.options[filters.selectedIndex].value }; } // Also allow for a regular input if (filters.nodeName=="INPUT" && filters.type=="text") { filters={ 'filter':"/^"+filters.value+"/" }; } // Force filters to be an array if (typeof(filters)=="object" && !filters.length) { filters = [filters]; } // Convert regular expression strings to RegExp objects and function strings to function objects for (var i=0,L=filters.length; i<L; i++) { var filter = filters[i]; if (typeof(filter.filter)=="string") { //If a filter string is like "/expr/" then turn it into a Regex if (filter.filter.match(/^\/(.*)\/$/)) { filter.filter = new RegExp(RegExp.$1); filter.filter.regex=true; } //If filter string is like "function (x) { ... }" then turn it into a function else if (filter.filter.match(/^function\s*\(([^\)]*)\)\s*\{(.*)}\s*$/)) { filter.filter = Function(RegExp.$1,RegExp.$2); } } // If some non-table object was passed in rather than a 'col' value, resolve it // and assign it's column index to the filter if it doesn't have one. This way, // passing in a cell reference or a select object etc instead of a table object // will automatically set the correct column to filter. if (filter && !def(filter.col) && (cell=getParent(o,"TD","TH"))) { filter.col = this.getCellIndex(cell); } // Apply the passed-in filters to the existing list of filters for the table, removing those that have a filter of null or "" if ((!filter || !filter.filter) && tdata.filters) { delete tdata.filters[filter.col]; } else { tdata.filters = tdata.filters || {}; tdata.filters[filter.col] = filter.filter; } } // If no more filters are left, then make sure to empty out the filters object for (var j in tdata.filters) { var keep = true; } if (!keep) { tdata.filters = null; } } // Everything's been setup, so now scrape the table rows return table.scrape(o); }; Вызов функции делаю, например, так: Код:
<th>Заголовок столбца<br><input onkeyup="Table.filter(this, this)" type="text"></th> Я так понимаю, надо копать в следующих строках функции: if (filters.nodeName=="INPUT" && filters.type=="text") { filters={ 'filter':"/^"+filters.value+"/" }; и/или if (typeof(filter.filter)=="string") { if (filter.filter.match(/^\/(.*)\/$/)) { filter.filter = new RegExp(RegExp.$1); filter.filter.regex=true; } Заранее спасибо! |
Часовой пояс GMT +3, время: 12:59. |