jqGrid multiselect, checked-box persist when move to the next page

前端 未结 6 860
忘了有多久
忘了有多久 2021-02-06 03:56

If you see jqGrid demo :

http://www.trirand.com/blog/jqgrid/jqgrid.html

Section : Advanced --> Multiselect

You\'ll see that the checked checkbox is not p

6条回答
  •  隐瞒了意图╮
    2021-02-06 04:42

    I set the following three options within the jqGrid call with these functions:

    onSelectRow: HandleSelectRow,
    onSelectAll: HandleSelectAll,
    gridComplete: HandleSelectedIds,
    

    My functions look like these:

    function HandleSelectRow(id, selected)
    {
        // Did they select a row or de-select a row?
        if (selected == true)
        {
            var currIndex = SELECTEDIDS.length;
            //selected_jq_ids_array[currIndex] = id;
            SELECTEDIDS.push(id); //SELECTEDIDS is a global variable I defined.
        }
        else
        {
            // Filter through the array returning every value EXCEPT the id I want removed.
            SELECTEDIDS = $.grep(SELECTEDIDS, function(value)
            {
                return value != id;
            });
        }
    }
    

    The next one:

    function HandleSelectAll(id, selected)
    {
        // Did they select or deselect?
        if (selected == true)
        {
            for (single_id in id)
            {
                // If the value is NOT in the array, then add it to the array.
                if ($.inArray(id[single_id], SELECTEDIDS) == -1)
                {
                    SELECTEDIDS.push(id[single_id]);
                }
            }
        }
        else
        {
            for (single_id in id)
            {
                // If the value is in the array, then take it out.
                if ($.inArray(id[single_id], SELECTEDIDS) != -1)
                {
                    SELECTEDIDS = $.grep(SELECTEDIDS, function (value)
                    {
                        return value != id[single_id];
                    });
                }
            }
        }
    }
    

    And the last one:

    function HandleSelectedIds()
    {
        if (SELECTEDIDS != null)
        {
            currentGridIds = new Array();
            currentGridIds = $("#lookupControl").getDataIDs();
    
            //Make Selection
            for (var e = 0; e < currentGridIds.length; e++)
                for (var i = 0; i < SELECTEDIDS.length; i++)
                    if (SELECTEDIDS[i] == currentGridIds[e])
                        jQuery("#lookupControl").setSelection(SELECTEDIDS[i], false);
    
            // TODO: Some logic on if all the rows on the current page are selected, then make sure to check the "Select All" checkbox.
            //var selectedIds = $("#lookupControl").getGridParam('selarrrow');  
        }
    }
    

提交回复
热议问题