jQuery UI Widgets › Forums › Grid › grid delete row
Tagged: angular grid, angular2 grid, bootstrap grid, deleterow, grid, javascript grid, jquery grid, jqwidgets grid, jqxgrid, rowid
This topic contains 2 replies, has 2 voices, and was last updated by josh 7 years, 1 month ago.
-
Authorgrid delete row Posts
-
Hi Community,
am trying to delete a record form grid using deletrow method:
here is my code snippetvar source = { localdata:data, datatype: "json", datafields: [ { name: 'external_id',map:'fields>external_id', type: 'number' }, #other data fields. ], id:'pk', deleterow: function (rowid,commit) { $.ajax({ type: "POST", dataType: 'json', url: "/delete_row/", data: {thedata:rowid}, success: function(data) { alert(data) commit(true); }, error:function(data){ alert("there was an error deleteting record") commit(false); } }); var dataAdapter = new $.jqx.dataAdapter(source); $("#jqxgrid").jqxGrid( { width: "100%", autoheight:true, source: dataAdapter, columnsresize: true, altrows: true, theme:'custom', pageable: true, filterable: true, filtermode: 'excel', sortable: true, groupable: true, columns: [ { text: 'Actions', datafield: 'Delete', columntype:'button',width:80,cellsrenderer:function () { return 'delete'; }, buttonclick: function (row) { // open the popup window when the user clicks a button. id = $("#jqxgrid").jqxGrid('getrowid', row); var offset = $("#jqxgrid").offset(); $("#popupWindow").jqxWindow({ position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60} }); // show the popup window. $("#popupWindow").jqxWindow('show'); } }, // initialize the popup window and buttons. $("#popupWindow").jqxWindow({ width: 250, resizable: false,theme:'custom', isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.01 }); $("#del").jqxButton({ theme: 'custom' }); $("#cancel").jqxButton({ theme: 'custom' }); // delete row. $("#del").bind('click', function () { var selectedrowindex = $("#jqxgrid").jqxGrid('getselectedrowindex'); var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount; if (selectedrowindex >= 0 && selectedrowindex < rowscount) { var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex); var commit = $("#jqxgrid").jqxGrid('deleterow', id); $("#popupWindow").jqxWindow('hide'); } }); $("#cancel").click(function () { $("#popupWindow").jqxWindow('hide'); });
If I delete record without first filtering grid,it works fine. if I filter grid say by company name and try deleting,it works for some rows and does not work for some.
Can anyone please assist?
Regards- This topic was modified 7 years, 1 month ago by josh.
Hello josh,
Could you check this row
if (selectedrowindex >= 0 && selectedrowindex < rowscount)
it is possible to missing some rows for this.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comHi Hristo,
I figured out that actually was the problem.
I removed this part&& selectedrowindex < rowscount
And it worked well.
Thanks -
AuthorPosts
You must be logged in to reply to this topic.