jqGrid with an editable checkbox column

后端 未结 6 2341
难免孤独
难免孤独 2020-12-23 20:41

When using jqGrid how do you force a cell to load in its editable view on page load as well as when it is clicked?

If you set up \'cell editing\' like below, the che

6条回答
  •  情深已故
    2020-12-23 20:52

    I had the same problem and I suppose that I found a good solution to handle checkbox click immediately. The main idea is to trigger editCell method when user clicks on the non-editable checkbox. Here is the code:

            jQuery(".jqgrow td").find("input:checkbox").live('click', function(){
                var iRow = $("#grid").getInd($(this).parent('td').parent('tr').attr('id'));
                var iCol = $(this).parent('td').parent('tr').find('td').index($(this).parent('td'));
                //I use edit-cell class to differ editable and non-editable checkbox
                if(!$(this).parent('td').hasClass('edit-cell')){
                                       //remove "checked" from non-editable checkbox
                    $(this).attr('checked',!($(this).attr('checked')));
                            jQuery("#grid").editCell(iRow,iCol,true);
                }
        });
    

    Except this, you should define events for your grid:

                afterEditCell: function(rowid, cellname, value, iRow, iCol){
                //I use cellname, but possibly you need to apply it for each checkbox       
                    if(cellname == 'locked'){
                    //add "checked" to editable checkbox
                        $("#grid").find('tr:eq('+iRow+') td:eq('+iCol+') input:checkbox').attr('checked',!($("#regions").find('tr:eq('+iRow+') td:eq('+iCol+') input:checkbox').attr('checked')));
                                //trigger request
                        jQuery("#grid").saveCell(iRow,iCol);
                    }   
                }, 
    
                afterSaveCell: function(rowid, cellname, value, iRow, iCol){
                    if(cellname == 'locked'){
                        $("#grid").find('tr:eq('+iRow+') td:eq('+iCol+')').removeClass('edit-cell');
                    }   
                }, 
    

    Then your checkbox will send edit requests every time when user clicks on it.

提交回复
热议问题