Author Topic: DeletRow function giving erroe  (Read 1557 times)

sshede

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 41
    • View Profile
DeletRow function giving erroe
« on: May 03, 2021, 03:47:14 pm »
Hi,

I use below code.
var grid =  $("#grid_json").pqGrid('getInstance').grid
$("#grid_json").pqGrid("deleteRow", { rowIndx: 1 });

but giving below error
Cannot read property 'element' of undefined

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: DeletRow function giving erroe
« Reply #1 on: May 03, 2021, 04:14:04 pm »
Could you share more details:

Which one of the 2 lines of source code is causing error.

Please share stack trace of the error.

Please share a jsfiddle.

sshede

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: DeletRow function giving erroe
« Reply #2 on: May 03, 2021, 06:30:29 pm »
Hi
I use below demo code . but not working deleteRow functionality.

$(function () {
        var data = [
            { rank: 1, company: 'Exxon Mobil', revenues: 339938.0, profits: 36130.0 },
            { rank: 2, company: 'Wal-Mart Stores', revenues: 315654.0, profits: 11231.0 },
            { rank: 3, company: 'Royal Dutch Shell', revenues: 306731.0, profits: 25311.0 },
            { rank: 4, company: 'BP', revenues: 267600.0, profits: 22341.0 },
            { rank: 5, company: 'General Motors', revenues: 192604.0, profits: -10567.0 },
            { rank: 6, company: 'Chevron', revenues: 189481.0, profits: 14099.0 },
            { rank: 7, company: 'DaimlerChrysler', revenues: 186106.3, profits: 3536.3 },
            { rank: 8, company: 'Toyota Motor', revenues: 185805.0, profits: 12119.6 },
            { rank: 9, company: 'Ford Motor', revenues: 177210.0, profits: 2024.0 },
            { rank: 10, company: 'ConocoPhillips', revenues: 166683.0, profits: 13529.0 },
            { rank: 11, company: 'General Electric', revenues: 157153.0, profits: 16353.0 },
         
        ];
        var frozenRows = [];

        var obj = {
            scrollModel: { autoFit: true },
            showTitle: false,
            resizable: true,
            freezeRows: 2,
            //showHeader: false,
            height: 400,
           
            colModel: [
                { title: "Rank", width: 100, dataType: "integer", dataIndx: "rank" },
                { title: "Company", width: 200, dataType: "string", dataIndx: "company" },
                { title: "Revenues", width: 150, dataType: "float", dataIndx: "revenues", format: '#.0' },
                { title: "Profits", width: 150, dataType: "float", dataIndx: "profits", format: '#.0' }
            ],
            dataModel: { data: data },
            create: function () {
                this.widget().find(".frozen").val(this.option('freezeRows'));
            },
            toolbar: {
                items: [                   
                    {
                        type: 'select',
                        label: 'Select number of frozen rows: ',
                        cls: 'frozen',
                        options: [0, 1, 2, 3, 4, 5, 6, 7, 8],
                        listener: function (evt) {
                            this.option("freezeRows", $(evt.target).val());
                            this.refresh();
                        }                                           
                    },
                    { type: 'separator' },
                    {
                        type: 'checkbox',
                        attr: 'id="sort_all_chk"',
                        label: 'Exclude frozen rows while sorting'
                    },
               {
                  type: 'button',
                  label: 'delete',
                  listener: function(){
                     var grid =  $("#grid_json").pqGrid('getInstance').grid
                      grid.deleteRow({ rowIndx: 4 } );
                  }
                    }
                ]
            }
        };
        $("#grid_freeze_rows").pqGrid(obj);

    });

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: DeletRow function giving erroe
« Reply #3 on: May 03, 2021, 06:54:47 pm »
Selectors don't match in your code: #grid_json / #grid_freeze_rows , they should be same.

Alternatively this context can be used.

Code: [Select]
  this.deleteRow({ rowIndx: 4 } );