jqxGrid按钮格式

时间:2015-07-16 14:17:52

标签: javascript jquery jqxgrid

我希望使用cellrender来渲染我自己的按钮,使用类似下面的代码:

 $("#jqxgrid").jqxGrid(
        {
            width: 850,
            source: dataAdapter,
            columnsresize: true,
            columns: [
              { text: 'Name', datafield: 'firstname', width: 120 },
              { text: 'Last Name', datafield: 'lastname', width: 120 },
              { text: 'Product', datafield: 'productname', width: 180 },
              { text: 'Quantity', datafield: 'quantity', width: 80, cellsalign: 'right' },
              { text: 'Unit Price', datafield: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' },
              { text: 'Total', datafield: 'total', cellsalign: 'right', cellsformat: 'c2' },
              {
                  text: 'Edit', width: 100, height: '100%', datafield: 'Name', columntype: 'button',
                  cellsrenderer: function (cellvalue, options, rowObject) {
                      return '<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="">Edit</button>';
                  },
                  buttonclick: function (row) {
                      var data = $('#jqxgrid').jqxGrid('getrowdata', row);
                      alert(data.firstname);
                  }
              }
            ]
        });

正如您所看到的,我正在尝试在细胞渲染器中渲染一个按钮,以便我可以显示模态形式。

1 个答案:

答案 0 :(得分:0)

You can't use a cellsrenderer like that with the button columntype and buttonclick handler. You can only return the text to be displayed in the button. Your cellsrenderer would look like the following:

cellsrenderer: function() {
  return 'Edit';
}

As far as including your bindings to make the modal work, you'll have to do it another way