Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.5K
Views
jqgrid: multiselect and disable check (conditional)


I love jqGrid but sometimes things seem more complicated than they should be.
What I would like to achieve is to have a checkbox on each row so that a user can choose which rows are going to be submitted/processed.
I need, though, to block some checkboxes cause the user has no authorization on that particular row, maybe.

I've tried to set multiselect: true and then I've tried to hide the checkbox:

loadComplete: function (data) {
    if (data.rows.length > 0) {
        for (var i = 0; i < data.rows.length; i++) {
            if (data.rows[i].cell[7] == 'false') {
                $("#jqg_OrdersGrid_" + data.rows[i].id).css("visibility", "hidden");
            }
        }
    }
},

and it works well but, still, .jqGrid('getGridParam', 'selarrrow') give me the selected rows, even if they haven't been checked.
Is there any other way to have checkboxes which are enabled/disabled and a way to know which ones have been checked?

thanks

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I would suggest you to disable some checkboxed from the be selectable with respect of "disabled" attribute. To make full implementation you will need

  1. set "disabled" inside of loadComplete event handle
  2. additionally prevent selection of disabled rows inside beforeSelectRow event handle
  3. to have support of "select all" checkbox in the header of the multiselect column implement onSelectAll event handle which fix selection of disabled rows.

The corresponding demo can you see here. The most important part of the code is here:

var grid = $("#list10"), i;
grid.jqGrid({
    //...
    loadComplete: function() {
        // we make all even rows "protected", so that will be not selectable
        var cbs = $("tr.jqgrow > td > input.cbox:even", grid[0]);
        cbs.attr("disabled", "disabled");
    },
    beforeSelectRow: function(rowid, e) {
        var cbsdis = $("tr#"+rowid+".jqgrow > td > input.cbox:disabled", grid[0]);
        if (cbsdis.length === 0) {
            return true;    // allow select the row
        } else {
            return false;   // not allow select the row
        }
    },
    onSelectAll: function(aRowids,status) {
        if (status) {
            // uncheck "protected" rows
            var cbs = $("tr.jqgrow > td > input.cbox:disabled", grid[0]);
            cbs.removeAttr("checked");

            //modify the selarrrow parameter
            grid[0].p.selarrrow = grid.find("tr.jqgrow:has(td > input.cbox:checked)")
                .map(function() { return this.id; }) // convert to set of ids
                .get(); // convert to instance of Array
        }
    }
);

UPDATED: Free jqGrid supports hasMultiselectCheckBox callback, which can be used to create multiselect checkboxes not for all rows of jqGrid. One can use rowattr to disable some rows additionally. As the result one will get the described above functionality in more simple way. It's recommended to use multiPageSelection: true option additionally for free jqGrid with local data (datatype: "local" or loadonce: true). The option multiPageSelection: true will hold the array selarrrow on paging. It allows "pre-select" some rows by filling the corresponding ids inselarrrow. See UPDATED part of the answer and the answer with the demo for additional information.

over 4 years ago · Santiago Trujillo Report

0

Great answer from Oleg, I would also add code to deselect disabled rows, complete onSelectAll function below.

onSelectAll: function(aRowids,status) {
    if (status) {
        // uncheck "protected" rows
        var cbs = $("tr.jqgrow > td > input.cbox:disabled", grid[0]);
        cbs.removeAttr("checked");

        //modify the selarrrow parameter
        grid[0].p.selarrrow = grid.find("tr.jqgrow:has(td > input.cbox:checked)")
            .map(function() { return this.id; }) // convert to set of ids
            .get(); // convert to instance of Array

        //deselect disabled rows
        grid.find("tr.jqgrow:has(td > input.cbox:disabled)")
            .attr('aria-selected', 'false')
            .removeClass('ui-state-highlight');
    }
}
over 4 years ago · Santiago Trujillo Report

0

For people (like me) that end up on this answer after searching on Google, there is a very easy solution to this problem since jqGrid 4.0.0.

It's enough to add the css-class 'ui-state-disabled' to the row that you don't want to be selected. See The changelog of jqGrid 4.0.0. And you could still combine that with hiding or disabling the checkbox.

    var $jqgrid = $("#jqgridselector");         
    //loop through all rows
    $(".jqgrow", $jqgrid).each(function (index, row) {
        var $row = $(row);
        if ($row === condition) {
            //Find the checkbox of the row and set it disabled
            $row.find("input:checkbox").attr("disabled", "disabled");
            //add class ui-state-disabled, because thats how jqGrid knows not to take them into account for selection
            $row.addClass("ui-state-disabled");
            //I overwrite the opactity of the ui-state-disabled class to make the row look 'normal'
            $row.css("opacity", 1);
            }
        });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!