Author Topic: AddRow Error Hep me  (Read 2712 times)

OlottSoft

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 7
    • View Profile
AddRow Error Hep me
« on: May 08, 2020, 12:29:33 pm »
My source:

function addRow() {
    var rowData = [{ rivername: '', organizationname: '', regdate: '', useyn:'1', riverseq:'', orgseq:'1' }]; //empty row template
    var rows = grid.getRowsByClass({ cls: 'pq-row-edit' });
    if (rows.length > 0) {//already a row currently being edited.
       var rowIndx = rows[0].rowIndx;

        //focus on editor if any
        grid.editFirstCellInRow({ rowIndx: rowIndx });
    }
    else {
        //append empty row in the first row.                           
        rowindex = grid.addRow({ rowIndxPage: 0, rowData: rowData, checkEditable: false });

        //start editing the new row.
        editRow();
    }
}

Error message :
    pqgrid.dev.js:4823 Uncaught TypeError: Cannot read property 'length' of undefined
    at t.paramquery.cRefresh.addRowIndx (pqgrid.dev.js:4823)
    at e.<computed>.<computed>.<anonymous> (pqgrid.dev.js:4783)
    at n (pqgrid.dev.js:402)
    at e.<computed>.<computed>.e._trigger (pqgrid.dev.js:424)
    at e.<computed>.<computed>.a.refreshDataFromDataModel (pqgrid.dev.js:2305)
    at e.<computed>.<computed>.a.refreshView (pqgrid.dev.js:2468)
    at e.<computed>.<computed>.n.addRow (pqgrid.dev.js:7309)
    at addRow (orgriverlist.do:385)
    at HTMLAnchorElement.onclick (VM370 orgriverlist.do:154)

Help me!!!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6313
    • View Profile
Re: AddRow Error Hep me
« Reply #1 on: May 08, 2020, 12:45:17 pm »
Please correct rowData

Code: [Select]
var rowData = { rivername: '', organizationname: '', regdate: '', useyn:'1', riverseq:'', orgseq:'1' }; //empty row template

OlottSoft

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: AddRow Error Hep me
« Reply #2 on: May 08, 2020, 05:42:53 pm »
After correction, the result is the same.
The code is as follows.
Thank you.

    var orgdata = [
        { rivername: '한강', orgseq: '1', regdate: '2020-05-07', useyn:'1', riverseq:'1'},
        { rivername: '영산강', orgseq: '2', regdate: '2020-05-04', useyn:'1', riverseq:'1' }
    ];

 obj.colModel = [
        { title: "강이름", width: 300, dataType: "string", align: "center", dataIndx: "rivername"},
        { title: "관리관청", width: 200, align: "center", dataIndx: "orgseq"
           , editor: {
              type:"select",
              labelIndx: "orgname",
              valueIndx: "orgseq",
              //prepend: { "": "Default" },   // 선택이 없을 경우 처리 (예: 전체)
              options: orglist
           }
           , render: function(ui){
              var cellData = ui.cellData;
              if (cellData != null && cellData != "") {
                 return orglist.find(function(item){
                    return item.orgseq == cellData;
                 }).orgname;
              }
           //   else {
           //      ui.rowData.itemtype = "Default";
            //       return "Default";
           //   }
           }
        },
        { title: "등록일", width: 100, dataType: "string", align: "center", editable: false,dataIndx: "regdate" },
        { title: "사용여부", width: 20, dataType: "string", align: "center", editable: false,dataIndx: "useyn" },
        { title: "riverseq", width: 20, dataType: "int", align: "center", editable: false,dataIndx: "riverseq", hidden: true }
       
    ];

//called by add button in toolbar.
function addRow() {
   
   
    var rowData = { rivername: '', orgseq: '1', regdate: '', useyn:'1', riverseq:'' }; //empty row template
   
   //grid.addRow({newRow:rowData, rowIndx:0, history:true});
   
    var rows = grid.getRowsByClass({ cls: 'pq-row-edit' });
    if (rows.length > 0) {//already a row currently being edited.
       var rowIndx = rows[0].rowIndx;

        //focus on editor if any
        grid.editFirstCellInRow({ rowIndx: rowIndx });
    }
    else {
        //append empty row in the first row.                           
        rowindex = grid.addRow({ rowIndxPage: 0, rowData: rowData, checkEditable: false });

        //start editing the new row.
        editRow();
    }
   
   
    viewButton(1);      // type 0:init, 1: new, 2:modify
}

result:
pqgrid.dev.js:4823 Uncaught TypeError: Cannot read property 'length' of undefined
    at t.paramquery.cRefresh.addRowIndx (pqgrid.dev.js:4823)
    at e.<computed>.<computed>.<anonymous> (pqgrid.dev.js:4783)
    at n (pqgrid.dev.js:402)
    at e.<computed>.<computed>.e._trigger (pqgrid.dev.js:424)
    at e.<computed>.<computed>.a.refreshDataFromDataModel (pqgrid.dev.js:2305)
    at e.<computed>.<computed>.a.refreshView (pqgrid.dev.js:2468)
    at e.<computed>.<computed>.n.addRow (pqgrid.dev.js:7309)
    at addRow (orgriverlist.do:436)
    at HTMLAnchorElement.onclick (VM1124 orgriverlist.do:180)

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6313
    • View Profile
Re: AddRow Error Hep me
« Reply #3 on: May 08, 2020, 06:54:31 pm »
Please share a jsfiddle so that I can look into it.

OlottSoft

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: AddRow Error Hep me
« Reply #4 on: May 09, 2020, 03:03:47 am »
Sorry
I don't know how to use jsfiddle.

After debugging, I tried to fix it because the 'i' in line number '4822' in 'pqgrid.dev.js' was undefined.
Can I do this?
Of course, it becomes 'addrow' without problems.

pqgrid.dev.js 
4820     addRowIndx: function(t) {
4821            for (var e, n = this.that, r = n.options.dataModel, i = r.dataUF, o = n.get_p_data(), a = o.length; a--;) e = o[a], e && (e.pq_ri = a);
4822            if (t) ---> changed if(t && i)
4823                for (a = i.length; a--;) delete i[a].pq_ri
4824        },

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6313
    • View Profile
Re: AddRow Error Hep me
« Reply #5 on: May 11, 2020, 01:16:37 pm »
Please use this jsfiddle to reproduce the error.

https://jsfiddle.net/nfpdo18q/