jQWidgets Forums

jQuery UI Widgets Forums Grid Select filtered rows, again

This topic contains 1 reply, has 2 voices, and was last updated by  Christopher 8 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Select filtered rows, again #85857

    mcseemcher
    Participant

    Hi!

    I’ve changed logics of filtering in my grid to use multiply values separated by commas. Filtering works fine, but when I start to retrieve selected rows it’s going wrong.

    So, when I do $('#jqxgrid').jqxGrid('getselectedrowindexes'); it returns an array of indexes in FILTERED grid, so when I do to retrieve data $('#jqxgrid').jqxGrid('getrowdata', sel[0]) I get wrong results.

    When I do not override filter definition in source that does not happen. getselectedrowindexes returns indexes from non filtered data.

    How do I get non-filtered Indexes of selected rows when grid is filtered?

    var source = {
    					datatype: 'json',
    					localdata: grid,					
                                            filter: function (filters, data, length) {
    				        var filtereddata = new Array();
    				        var filterslength = filters.length;
    				        for (row = 0; row < length; row++) {
    				            var datarow = data[row];
    				            var filterresult = undefined;
    				            // loop through the filters and evaluate the value.
    				            for (j = 0; j < filterslength; j++) {
    				                var filter = filters[j].filter;
    				                var value = datarow[filters[j].datafield];
    				                var appliedFilterValue = filters[j].filter.getfilters()[0].value;
    				                if (appliedFilterValue[appliedFilterValue.length-1] === ",") appliedFilterValue = appliedFilterValue.slice[0,-1]
    				                var valarray = appliedFilterValue.split(',');
    				                if (valarray.length > 1){
    				                	var SplittedFilterGroup = new $.jqx.filter();
    
    				                	for (k = 0; k < valarray.length; k++) {
    										var YetAnotherFilter = SplittedFilterGroup.createfilter('stringfilter', valarray[k], 'contains');
    										var result = YetAnotherFilter.evaluate(value);
    										if (filterresult == undefined) filterresult = result;
    						                else {
    						                        filterresult = filterresult || result;
    						                	}
    						                if (filterresult == true) break;	
    				                	}
    				                }
    				                else {						                
    					                var result = filter.evaluate(value);
    					                if (filterresult == undefined) filterresult = result;
    					                else {
    					                    if (filter.operator == 'or') {
    					                        filterresult = filterresult || result;
    					                    }
    					                    else {
    					                        filterresult = filterresult && result;
    					                    }
    					                }
    						        }        
    				            }
    				            if (filterresult) {
    				                filtereddata[filtereddata.length] = datarow;
    				            }
    				        }
    				        return filtereddata;
    				    }
    Select filtered rows, again #85900

    Christopher
    Participant

    Hi mcseemcher,

    I think there’s a better way to do what you need. You can use the filter property of the jqxGrid, here is an example:
    http://jsfiddle.net/bn4okvy3/6/

    Keep in mind that “indexOf()” is a case sensitive function. This example gives the correct indexes of the selected rows after filtering.

    Best Regards,
    Christopher

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.