Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete rows in jqgrid

Tags:

jquery

jqgrid

I have just begun using jqGrid, and I want to delete rows using a custom delete button. I am using the code snippet below:

try {
        var cellValue;
        var id;
        jQuery("#editDataGridList").jqGrid({
            datatype: "local",
            width: 900,
            height: 270,
            colNames: ['Action', 'Interview id', 'Date of observation', 'Name of enumerator'],
            onSelectRow: function (id) {
                debugger;
                var rowData = jQuery(this).getRowData(id);                   
                cellValue = rowData['InterviewId'];
            },
            colModel: [                
                 {
                     name: 'actions', index: 'InterviewId', sortable: false,
                     formatter: function (rowId, cellval, colpos, rwdat, _act) {

                         return "<input type='button' id='btnid' value='delete' class='btn' onClick='deleteRecords(" + cellValue + ");' />";

                     }
                 },
                { name: 'InterviewId', index: 'InterviewId' },
                { name: 'Date', index: 'Date' },
                { name: 'NameOfEnum', index: 'NameOfEnum' }
            ],

            multiselect: false,
            caption: "Edit already entered data"
        });
    }
    catch (e) {
        alert(e.message);
    }

The above code uses this function call to pass the selected row value for deletion

function deleteRecords(rowData) {
    alert(rowData);
}

Unfortunately the rowData value is undefined. How can I use the same structure to delete the rows?

like image 838
JoseLuke Avatar asked Aug 20 '13 11:08

JoseLuke


1 Answers

you can delete row using

$('#editDataGridList').jqGrid('delRowData',rowid);
like image 188
Waqas Memon Avatar answered Sep 27 '22 18:09

Waqas Memon