Rafael Carrillo
Rafael Carrillo

Reputation: 2883

Adding "Options" column to JQGrid?

I'm using JQuery Plugin for Struts 2 to show a grid (jqGrid) but I want to add a column with some options like edit, delete, etc.

I'm following this guide from official documentation for jqGrid

http://trirand.com/blog/jqgrid/jqgrid.html

I'm subscribing the event when grid loads to add content to each row, but instead render a button just shows the plain html code:

$(function(){
                $.subscribe("addOptions",function(){
                var ids=$("#procedimientos").jqGrid('getDataIDs');
                for(var i=0;i<ids.length;i++){
                    be = "<input style='height:22px;width:20px;' type='button' value='E' />";
                    $("#procedimientos").jqGrid('setRowData',ids[i],{opciones: be});
                }
            });

$("#procedimientos") it's my grid

can you help me :) ?

Upvotes: 0

Views: 701

Answers (1)

Kishore Kumar
Kishore Kumar

Reputation: 939

We can render the button using formatter callback function like below

colNames : 
      [ 'Name1',  
        'name2',  
      ],
    colModel : [ 
      {name : 'name1',index : 'id',width : 50,align : 'center'} , 
      {name : 'name2',index : 'name2',editable : false,width : 120,formatter:
      function (cellvalue, options, rowObject) { 
      if(cellvalue=='cond1'){
      return "<\input type='button' value='Add' onclick='func1(" + options.rowId + ")'/>"; 
    } 
    else if(cellvalue == 'cond2'){ 
    return "<\input type='button' value='Delete' onclick='func2(" + options.rowId + ")'/>"; 
    } 
    }
} 
    ]

Upvotes: 1

Related Questions