I use loadonce to get all the data in front, and then sort and filter locally.
One of the values in my column is an array of objects. In the colModel option, I use a formatting function that looks like this:
function my_formatter(cellValue) { return $.map(cellValue, function(element) {return element.human_readable_name;}).join(', '); }
I also use a custom sort function that simply returns the length of the array.
The problem is that toolbar filtering and multi-threaded dialog filtering do not work. They seem to be looking for [objects] .toString (), not a formatted value. Therefore, I get hits when I search for “object of object”, but not when searching for actual values.
Is there a way to force local filtering to use a formatted value?
Change based on Oleg’s answer:
I adapted Oleg's code to add filter formatting for each column. It seems to work well. I deleted the _toStr replacement because it did not seem necessary - I think it used to change the search term (which makes sense in the case of the accent for Oleg's accent, but not mine).
// Causes local filtering to use custom formatters for specific columns. // formatters is a dictionary of the form: // { "column_name_1_needing_formatting": "column1FormattingFunctionName", // "column_name_2_needing_formatting": "column2FormattingFunctionName" } // Note that subsequent calls will *replace* all formatters set by previous calls. function setFilterFormatters(formatters) { function columnUsesCustomFormatter(column_name) { for (var col in formatters) { if (col == column_name) return true; } return false; } var accessor_regex = /jQuery\.jgrid\.getAccessor\(this\,'(.+)'\)/; var oldFrom = $.jgrid.from; $.jgrid.from = function(source, initialQuery) { var result = oldFrom(source, initialQuery); result._getStr = function(s) { var column_formatter = 'String'; var column_match = s.match(accessor_regex, '$1'); if (column_match && columnUsesCustomFormatter(column_match[1])) { column_formatter = formatters[column_match[1]]; } var phrase=[]; if(this._trim) { phrase.push("jQuery.trim("); } phrase.push(column_formatter+"("+s+")"); if(this._trim) { phrase.push(")"); } if(!this._usecase) { phrase.push(".toLowerCase()"); } return phrase.join(""); } return result; }; }
And it is called like this:
setFilterFormatters({'column_with_array_of_objects':'my_formatter'});
Testing assumes that this works for “contains,” “does not contain,” “equal,” “not equal” (and probably “starts with” and other simple string comparisons — but I don't use them).
Thank you Oleg.