jQuery UI Widgets Forums Grid Programmatically set filters working but not visible in the filter menu?

This topic contains 3 replies, has 2 voices, and was last updated by  svetoslav_borislavov 1 year, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author

  • Bungle1981
    Participant

    I have the following function which takes a snapshot of any active filters on a ‘master’ grid, updates the underlying data (this is mainly to reset any nested grids which have already been initialized/populated via ‘initrowdetails’ so they can be re-initialized/refreshed after the function has run, and then re-applies the original filters.

    function updateUsageDuration() {
        // Take snapshot of active filters
        const activeFilters = [];
        $.each($("#jqxgrid").jqxGrid('getfilterinformation'), (index, filterInfo) => {
            let value = filterInfo.filter.filtervalue? filterInfo.filter.filtervalue: filterInfo.filter.getfilters()[0].value;
            let condition = filterInfo.filter.filtervalue? filterInfo.filter.comparisonoperator: filterInfo.filter.getfilters()[0].condition;
            activeFilters.push({
                columnName: filterInfo.filtercolumn,
                filterValue: value.toLowerCase(),
                filterCondition: condition.toLowerCase(),
            });
        });
        
        // Update bound data / reset init row etc
        $("#jqxgrid").jqxGrid('updatebounddata');
        
        // Reapply filters                
        activeFilters.forEach((filter) => {
            let filtergroup = new $.jqx.filter();
            let filtervalue = filter.filterValue;
            let filtercondition = filter.filterCondition;
            let filter1 = filtergroup.createfilter('stringfilter', filtervalue, filtercondition);
            $("#jqxgrid").jqxGrid('addfilter', filter.columnName, filter1);
        });
        $("#jqxgrid").jqxGrid('applyfilters');
        $("#jqxgrid").jqxGrid('refreshfilterrow');
    }

    After running this function, the page displays how I would expect, with the filters set correctly after updating the bound data, however in the built in jqxgrid filter menu, the filter value doesn’t appear any more. While everything still works, from a user perspective I’d prefer to see the value in there.

    Does anyone know how to make sure this value is visible in the jqxgrid filter menu please?

    Hi,

    Here is your updated version: http://jsfiddle.net/n3d0u4of/1/
    You forgot to add filter1 to the filter group with a condition.
    Also, you should add the filter group, not the filter1

    I hope this helps!

    Best regards,
    Svetoslav Borislavov

    jQWidgets Team
    https://www.jqwidgets.com/


    Bungle1981
    Participant

    Thanks! Out of interest, I’m really having issues with something that this code is essentially working around and it would be good to understand how to do ‘properly’ without the workaround.

    I have a drop down box outside of my main grid which contains a value which is used to get the data for ‘initrowdetails’ for any nested grid(s). When I change the value in this dropdown box, ideally I’d like any nested grids already created to be updated with data based on the new value in the drop down – essentially redoing the ‘initrowdetails’ actions as far as getting updated data etc.

    The only way I have been able to get anywhere close to this, is to call updatebounddata on the master grid (‘#jqxgrid’) and then manually re-open the target row which will then show the updated nested grid. I’ve tried doing this via jqxgrid methods and vanilla JS DOM manipulation but neither seems to work properly.

    Is there a reliable method to call initrowdetails or an equivalent to refresh the bound data for a nested grid?

    Hi,

    The initrowdetails is called only when the row details are expanded and the details are going to be rendered.
    You can update the data in the master grid with the updatebounddata and the initrowdetails should change also because the data of the row is changed after the update.

    Best regards,
    Svetoslav Borislavov

    jQWidgets Team
    https://www.jqwidgets.com/

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

You must be logged in to reply to this topic.