Yass
Yass

Reputation: 602

jqGrid - Delete issue

I have simple JqGrid

  $j("#gridTemp").jqGrid({
    jsonReader: {
        id: 'AppID' + 'Name',
        repeatitems: false
    },
    url: GetData,
    datatype: "json",
    colNames: ['Col1', 'Col2'],
    colModel: [
                { name: 'Col1'},
              { name: 'Col2'}
            ],
    rowNum: 10,
    autowidth: true,
    rowList: [10, 20, 30],
    pager: '#pager1',
    }).navGrid('#pager1', { edit: false, add: false, del: true, search: false }, {}, {}, { url: DeleteAddress });

}

and trying to get delete button click event

$j('#del_gridTemp').click(function () { 
        alert($j('#gridTemp').jqGrid('getGridParam', 'selarrrow')); 
    });

for some reason its not working. Any help appriciated.

Upvotes: 2

Views: 4592

Answers (2)

Oleg
Oleg

Reputation: 221997

I don't know what is the error, but I hope the demo will help you.

First you use selarrrow parameter, so I suppose you want to have multiselect grid. So I added multiselect: true parameter in the code. You original code with $('#del_gridTemp').click(function () {...}); works in my demo. I modified just the text of the alerts. If you for example select rows having "test4", "test2", "test12" you will see first the message like

enter image description here

after you click "OK" button and then "Delete" button in the confirmation dialog you will see the next message

enter image description here

from the onclickSubmit callback function which I recommend you to use. To code looks like

$("#gridTemp").jqGrid('navGrid', '#pager', {refreshstate: 'current', add: false, edit: false, del: true},
    {},
    {},
    { url: '/DeleteAddress',
        onclickSubmit: function (options, postdata) {
            alert('in onclickSubmit: postdata=' + postdata);
            return { myData: 'Hello'};
        }});

Inside of onclickSubmit method I show additionally how to append the information which will be sent with additional information.

I don't have any server code under the URL '/DeleteAddress', but in any tools like Fiddler of Firebug you will be able to the the format of data which will be posted. It's the data in x-www-form-urlencoded form:

myData=Hello&oper=del&id=4%2C2%2C12

which are in decoded form:

myData=Hello
oper=del
id=4,2,12

I think it should be close to what you need.

Upvotes: 2

sinemetu1
sinemetu1

Reputation: 1726

See jqGrid methods here. You can delete rows like this:

$('#the_button').click(function () {
    //get selected Ids returns like: ["1", "2", "3"]
    var selectedIds = $('#gridTemp').jqGrid('getGridParam', 'selarrrow');

    //iterate over each id and delete the corresponding row
    $.each(selectedIds, function (index) {
        $('#gridTemp').jqGrid('delRowData', selectedIds[index]);
    });
});

Upvotes: 0

Related Questions