简体   繁体   中英

How to disable inline and form editing for posted rows in jqgrid

I'm looking for a way to disable editing of jqGrid rows where isPosted column has value true.

Both form and inline editing with actions formatter or double clicking in row are used. All kinds of editing needs to be disabled. I tried code below in jqGrid loadcomplete.

This does not disable form editing. Also double click in posted row shows save and cancel buttons (all columns are in readonly mode).

How to disable all kind of row editing for posted rows ? jqGrid is populated from remote jqson data.

  loadCompete: function () {
    var
      postedCol = getColumnIndexByName($grid, 'isPosted'),
      cRows = $grid[0].rows.length,
      iRow,
      row,
      className,
      isPosted,
      cm = $grid.jqGrid('getGridParam', 'colModel'),
      l,
      iActionsCol = getColumnIndexByName($grid, '_actions');

    l = cm.length;
    for (iRow = 0; iRow < cRows; iRow = iRow + 1) {
            row = $grid[0].rows[iRow];
            className = row.className;
            isPosted = false;
            if ($.inArray('jqgrow', className.split(' ')) > 0) {
              isPosted = $(row.cells[postedCol]).find(">div>input:checked").length > 0;
              if (isPosted) {
                    if ($.inArray('jqgrid-postedrow', className.split(' ')) === -1) {
                        // todo: how to disable row editing and inline edit actions buttons.
                        // why those two lines do not disable
                        row.className = className + ' jqgrid-postedrow not-editable-row';
                        $(row.cells[iActionsCol]).attr('editable', '0'); 
                        $(row.cells[iActionsCol]).find(">div>div.ui-inline-del").hide();
                        $(row.cells[iActionsCol]).find(">div>div.ui-inline-edit").hide();
                    }
                }
            }
        }


css file:

.jqgrid-postedrow
{
    background-color: #FFFFD0;
    background-image: none;
}

@Andrus, well you can check on gridComplete or LoadComplete about the value of isPosted, if it is true simply hide the edit buttons using jquery, and you can get the id of those buttons using developer tools right?

I had one similar requirement where in some rows i had to show edit button and in some rows i had to hide them based on data in jqgrid.

so i got the id of those buttons using developer tools and in loadComlete i checked the value of all the rows and hide the buttons. i think that can be work out for you also. and talking about onSelectRow or onDblClickRow check the value of isPosted, if its true, you should return false from your function else go with normal editing with something like this

jQuery("#grid_id").editRow( id, properties );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM