0

I have a JQGrid in which one of the columns I used font awesome icon[X] to perform delete row operation. Below is the code where I used delete() function, expected that when I click on the div element the function would hits but does not happened and getting an error in developer tool like "(function(event){DeselectMeasures(85)})", where 85 is the Id of my grid data.

Which is the best practice to perform this? Is there any alternative to produce [X] button as a last column and need to perform some operation before deleting?

$("#selectedMeasuresgridID").jqGrid({
            datatype: 'function',
            mtype: 'Post',
            colNames: [ 'Delete'],
            colModel: [
                { name: 'Delete', index: 'Delete', width: 50, editable: true, formatter: FACloseIcon, align: 'center' }
            ],
   rowNum: 10,
            rowList: [10, 20, 30, 40],
            height: '100%',
            viewrecords: true,
            caption: '',
            emptyrecords: 'No records to display',
            autowidth: true,
            loadComplete: function () {
                //operations
            }
        });

function FACloseIcon(cellvalue, options, rowObject) {
    return '<div onclick="Deselect(' + rowObject.Id + ')" class="fa fa-close deSelect" aria-hidden="true"></div>';
}

function Deselect(rowObject) {
    //I will write code accordingly
}
vinS
  • 1,417
  • 5
  • 24
  • 37
Virat
  • 111
  • 3
  • 14
  • Please, include in **every** question about jqGrid the information about the jqGrid *version*, which you use (can use) and about the *fork* of jqGrid ([free jqGrid](https://github.com/free-jqgrid/jqGrid), commercial [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version <=4.7). Free jqGrid, for example, have built-in support of Font Awesome 4.x. One need just include `iconSet: "fontAwesome"` option (see an example [here](http://free-jqgrid.github.io/getting-started/index.html#type_of_data_code)). – Oleg Jan 19 '17 at 07:41
  • One can use `actionsNavOptions` if you need to add custom buttons to `formatter: "actions"`. See [the demo](http://www.ok-soft-gmbh.com/jqGrid/OK/CustomActionButton.htm) and [this one](http://www.ok-soft-gmbh.com/jqGrid/OK/CustomActionButton1.htm), [the wiki article](https://github.com/free-jqgrid/jqGrid/wiki/Enhancement-of-formatter:%22actions%22#custom-action-buttons-in-free-jqgrid-49) and [the old answer](http://stackoverflow.com/a/29735149/315935). – Oleg Jan 19 '17 at 07:44
  • The origin of error of your current code could be **the place**, where you defined `Deselect` function. You can call only **global** function inside of `onclick` attribute. In other words, the `DeselectMeasures` function have to be declared on top level of your JavaScript code. In the way you will define `DeselectMeasures` as the property of `window` object (`window.DeselectMeasures`). One more remark, you posted the error about `DeselectMeasures` function and not about `Deselect`, which you use in `onclick` of the formatter `FACloseIcon` – Oleg Jan 19 '17 at 07:48
  • @oleg thank you, i will make sure the things in a correct manner and let you know once resolved. FYI-I have changed the on click function name in this post just o make sure clear and understandable, but forgot to change in error – Virat Jan 19 '17 at 16:31

0 Answers0