Skip to content Skip to sidebar Skip to footer

How To Filter Jqgrid Data But Not The Grid Itself

As far as I see, free-jqgrid uses jlinq to filter and search data. I am making my own filters, that are using grids postData in it's well-known format: { 'groupOp': 'AND', '

Solution 1:

Sorry, but I'm not sure what you need to implement. You can get lastSelectedData parameter to have the array of filtered and sorted data, based on the current filter. The full data are available via lastSelectedData parameter. The filters property of postData parameter gets you the current filter.

You asked "are there any public functions to get current query for grid?". You can use getGridParam method to get current query. I guess, that you want to get access to some internal structures close to jlinq, but it gives really no practical value. You can access the class via $.jgrid.from, but it's not really helpful. Practical one needs only to set new filter in postData.filters parameter, set search parameter to true and call .trigger("reloadGrid") to reload grid with new data.

If you need to filter or to sort some data yourself, then array methods filter and sort will be more effective. If the above information don't help you to solve your problem, please append your question with additional information, which describes the problem more detailed on an example and post me small comment.

Updated: I'm still not sure that I exactly understand what you want to implement. It seems to me that the most functionality of your JSFiddle demo can be removed if you use some free jqGrid options.

Look at https://jsfiddle.net/OlegKi/wqxyo579/25/, which used

colModel: [
    { name: 'name' },
    { name: 'surname' },
    { name: 'age' },
],
cmTemplate: {
    width: 100,
    autoResizable: true,
    stype: 'select',
    searchoptions: {
        generateValue: true,
        noFilterText: "(All)"
    }
},

It sets some default property on every column. Starting with version 4.14.0 free jqGrid supports generateValue: true property of searchoptions for columns having stype: 'select' (see here). Internally it works like another option of colModel: createColumnIndex: true, which generates the map from unique values in all columns having createColumnIndex: true. One can use getUniqueValueFromColumnIndex method to get the index for any column (like var indexName = $("#list").jqGrid("getUniqueValueFromColumnIndex", "name");). If one uses stype: 'select', searchoptions: { generateValue: true }, then filterToolbar build automatically <select> elements using the index. jqGrid uses internally oSv = $("#list")[0].generateValueFromColumnIndex(cmName, sep, delim); (see here). As the result, one can save a lot of customization using the feature.

The only thing, which one should don't forget in case of using createColumnIndex: true or generateValue: true: the index will be build after the data is loaded or reloaded. So one should call filterToolbarafter filling the data. If you load the data from the server with respect of loadonce: true option, then you should call filterToolbar better inside of loadCompleted callback (like in the demo). In case of direct loading of local data it's not needed. Just call filterToolbarafter filling the data.

Another alternative would be to use <datalist> instead of <select>. It allows to use <input> in the filter toolbar, but have functionality close to select or select2. See https://jsfiddle.net/OlegKi/wqxyo579/24/, where I used createColumnIndex: true, searchoptions: { sopt: [ "cn", "eq", "bw", "ew", "bn", "nc", "en" ], clearSearch: true, generateDatalist: true }. Datalists are implemented in different web browsers in a little different way and they have some disadvantages, but it's native implemented feature and so it works very quickly. One can use it with for example 1000 unique values and 10000 rows in the grid (I'd strictly recommend to use local data paging in the case and to use page size 10-25). Datalists with 1000 elements will still have good performance, much better as select2 for example.

Final remark. I see that you built colModelIndexesByNames to find column by name. The built-in parameter iColByName already exist in free jqGrid and be used internally. If p is reference to parameters of jqGrid (var p = $("#list").jqGrid("getGridParam")), then p.iColByName is the map, which gets column index by column name and p.colModel[p.iColByName.name] will represent the item in colModel, which corresponds "name" column.

Post a Comment for "How To Filter Jqgrid Data But Not The Grid Itself"