jQuery UI Widgets Forums Grid grid delete row

This topic contains 2 replies, has 2 voices, and was last updated by  josh 7 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • grid delete row #88074

    josh
    Participant

    Hi Community,
    am trying to delete a record form grid using deletrow method:
    here is my code snippet

     var 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

    grid delete row #88092

    Hristo
    Participant

    Hello josh,

    Could you check this row if (selectedrowindex >= 0 && selectedrowindex < rowscount) it is possible to missing some rows for this.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

    grid delete row #88095

    josh
    Participant

    Hi Hristo,
    I figured out that actually was the problem.
    I removed this part && selectedrowindex < rowscount
    And it worked well.
    Thanks

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.