0

Using jqGrid with multiselect: true how can I make each row checked or not according to what the DB returns?

I know that I can use on "loadcomplete" and loop though all elements that are already on the grid and checked them according to a hidden column value (or something like that.) However this is not what I am looking for (afterInsertRow is similar on the way that it is a "manualy" action to set the check value). I really need to set this checked or not while the grid "draws" the rows.

Is this possible?

4

2 回答 2

1

If you have not enabled gridview option, then there is an event afterInsertRow available for handling:

afterInsertRow: function(rowid, rowdata, rowelem) {
    // code for selection here
    // example:
    $('selector for grid').jqgrid('setSelection', rowid);
},

More details in the documentation: events and methods.

Update. Other option is to define custom formatter for the column model. Assuming objects that are coming from DB contain property named checked that determines whether the row is selected, code might look something like this:

colModel:[
    {
        name:'checked',
        formatter: function (cellvalue, options, rowObject) {
            if (cellvalue) {
                return '<input type="checkbox" checked="checked" />';
            }
            return '<input type="checkbox" />';
        }
    },
    // rest of column models
于 2013-04-15T09:55:08.843 回答
0

Use the template: "booleanCheckbox" property like below. , where available is the variable name from the backend.

{name:'available', hidden:false, width:30, sortable:true, search:false,
 template: "booleanCheckbox", resizable:false, formatoptions: {disabled : false}}
于 2021-07-07T18:16:18.207 回答