Author Topic: AddRow issue - cells getting dirty  (Read 2875 times)

kshipra

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 94
    • View Profile
AddRow issue - cells getting dirty
« on: April 02, 2018, 06:55:13 am »
Code: [Select]
var newRow = {};
                                    var dynamicId = Math.floor(Math.random() * 10) - 100;
                                    newRow.Id = dynamicId;
                                    newRow.Deprecated = false;
                                    newRow.IsTemplate = false;
                                    newRow.Exclude = false;
                                   
                                    //newRow.pq_rowcls = 'yellow';
                                    $grid.pqGrid("addRow", { rowData: newRow, rowIndxPage: 0, checkEditable: false, history: false });
                                    $grid.pqGrid("setSelection", null);
                                    $grid.pqGrid("setSelection", { rowIndxPage: 0, dataIndx: 'EventName' });
                                    $grid.pqgrid("editFirstCellInRow", { rowIndxPage: 0 });

Id is primary key set in dataModel.

When new row is added, the cells become dirty (red sign showing in upper left corner) and get added in updatelist and addlist. On ajax success call the response has addlist with new Id but it is not getting updated.

                               grid.commit({ type: 'add', rows: jsonRsp.addList });
                                grid.commit({ type: 'update', rows: jsonRsp.updateList });
                                grid.commit({ type: 'delete', rows: jsonRsp.deleteList });

I am not sure what I am doing wrong?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6299
    • View Profile
Re: AddRow issue - cells getting dirty
« Reply #1 on: April 02, 2018, 04:53:18 pm »
Primary key value of new rows should be set in remote script, not in browser side js.

kshipra

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 94
    • View Profile
Re: AddRow issue - cells getting dirty
« Reply #2 on: April 03, 2018, 05:08:08 pm »
Hi,

The reason I was setting Id on client side was because if user clicks on AddRow multiple times to add  multiple rows , pqgrid has primary key violation error. It needs recIndx column to be unique.


This code works for adding 1 row. But if user clicks AddRow button 4 times, i get primary key violation error from pqgrid. How can i add multiple rows ?

$grid.pqGrid("addRow",
                                        {
                                            //checkEditable: false,
                                            rowList: [
                                                {
                                                    newRow: {
                                                        Deprecated: false,
                                                        IsTemplated: false,
                                                        Exclude: false,                                                       
                                                        Id: undefined
                                                    },
                                                    rowIndx: 0,
                                                    pq_rowcls: 'yellow'
                                                }
                                            ]
                                        });
« Last Edit: April 03, 2018, 06:14:39 pm by kshipra »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6299
    • View Profile
Re: AddRow issue - cells getting dirty
« Reply #3 on: April 03, 2018, 07:16:19 pm »
Please try to remove Id field from newRow as below and share a jsfiddle and version of grid if still not resolved.

Code: [Select]
newRow: {
         Deprecated: false,
         IsTemplated: false,
         Exclude: false
},

kshipra

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 94
    • View Profile
Re: AddRow issue - cells getting dirty
« Reply #4 on: April 05, 2018, 10:39:10 am »
Thanks, that worked.