Search code examples
javascriptjqueryjqgrid

Create button JqGrid


I use JqGrid to build a table, when I select a line, I get the onSelectRow action. Also in the table there is a column with a button, which I create using the formatter. How do I make the onSelectRow event not work on click the button?

Formatter:

function btnCopyZn(rowId, cellValue, rowObject) 
{
   return "<button onClick='clickFunctionCopyZn(" + rowId + ")' class='btn btn-xs btn-default'>" 
          + '<sapn class="glyphicon glyphicon-copy"></span>' 
          + "</button>";
}

Function copy:

function clickFunctionCopyZn(rowId) 
{
   if (rowId != null) 
   {
     var input = document.createElement("input");
     input.value = rowId;
     document.body.appendChild(input);
     input.select();
     document.execCommand("Copy");
     document.body.removeChild(input);
   }
}

onSelectRow:

model.tableTreeGrid.setGridParam({
onSelectRow: function () 
{
// function
}
});

Solution

  • If you use Guriddo jqGrid then one possible solution is to use another event called beforeSelectRow.

    This event fire when the user click on the row, but before select them. This event should return boolean true or false. If the event return true the selection is done. If the event return false the row is not selected and any other action (except onCellSelect) if defined does not occur.

    Parameters passed to this event is is the rowid and event handler.

    $("#jqGrid").jqGrid({
    ...
       beforeSelectRow : function( rowid, ev ) {
          if( condition_not_to_selectrow) {
             return false;
          } else {
             return true;
          }
       },
    ...
    });