Author Topic: Editing multiple rows programmatically.  (Read 4008 times)

waldemarb

  • Newbie
  • *
  • Posts: 5
    • View Profile
Editing multiple rows programmatically.
« on: June 03, 2016, 02:23:28 am »
Hi,

I have a pqgrid that I would like to update in the following way:
1. I manually select few rows, by selecting check-boxes.
2. Above grid there is 1 drop-down and 2 buttons. 1st called 'Apply reviewer', 2nd called 'Save changes'.
3. I pick a value from a drop-down, and push the 1st button 'Apply reviewer'
4. Selected rows got new value.

The problem is, that the pqgrid does not acknowledges any change.
Red triangles are not visible and
  var isDirty = gridD.isDirty(); returns 'false' and
  var changes = gridD.getChanges({ format: "byVal" }); returns 0,0,0 objects and
  var changes2 = gridD.getChanges(); returns 0,0,0 objects.

But when I type something into cell, triangles are there.

Please help.
If you need more info please let me know.

Thank you very much.


« Last Edit: June 03, 2016, 03:00:02 am by waldemarb »

waldemarb

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Editing multiple rows programmatically.
« Reply #1 on: June 03, 2016, 07:26:27 pm »
Just forgot to add a code snipet that sets the values in selected rows:

   var sReviewerName;
        function setSelectedRecords() {   
           debugger;         
            sReviewerName = $('#rList').data('selected').text;
            sReviewerName = sReviewerName + '\u000D\u000A';
            //alert('sReviewerName' + '\u000D' + '\u25B4' );                               
            mySelection = myGrid1.pqGrid( "selection", { type:'row', method:'getSelection' });
           
            var rowData = null;           
           
            for (var i = 0; i < mySelection.length; i++)
            {                           
            rowData = myGrid1.pqGrid( "getRowData", {rowIndx: mySelection.rowIndx} );
            rowData.reviewer = sReviewerName;           
            myGrid1.pqGrid( "updateRow", {rowIndx: mySelection.rowIndx, row: rowData, track: true} );
            myGrid1.pqGrid( "refreshCell", { rowIndx: mySelection.rowIndx, dataIndx: 'reviewer' } );               
            }
            myGrid1.pqGrid( "setSelection", null );
        };
« Last Edit: June 03, 2016, 08:06:15 pm by waldemarb »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Editing multiple rows programmatically.
« Reply #2 on: June 04, 2016, 08:59:32 am »
Code: [Select]
  rowData.reviewer = sReviewerName;           

Since rowData is a reference to the row object, it updates the rowData before leaving a chance for updateRow to make a diff of the changes.


Instead try this:

Code: [Select]
  myGrid1.pqGrid( "updateRow", {rowIndx: mySelection.rowIndx, row: { reviewer: sReviewerName }} );

waldemarb

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Editing multiple rows programmatically.
« Reply #3 on: June 07, 2016, 01:01:12 am »
Code: [Select]
  rowData.reviewer = sReviewerName;           

Since rowData is a reference to the row object, it updates the rowData before leaving a chance for updateRow to make a diff of the changes.


Instead try this:

Code: [Select]
  myGrid1.pqGrid( "updateRow", {rowIndx: mySelection.rowIndx, row: { reviewer: sReviewerName }} );

Thank you very much. This worked for me.
Here is final version of this function, in case someone needs it:


        var sReviewerName;
        function setSelectedRecords() {   
           //debugger;         
            sReviewerName = $('#rList').data('selected').text;                             
            mySelection = myGrid1.pqGrid( "selection", { type:'row', method:'getSelection' });
           
            for (var i = 0; i < mySelection.length; i++)
            {            
            myGrid1.pqGrid( "updateRow", {rowIndx: mySelection[ i ].rowIndx, row: { reviewer: sReviewerName }} );
            myGrid1.pqGrid( "refreshCell", { rowIndx: mySelection[ i ].rowIndx, dataIndx: 'reviewer' } );                  
            }
            myGrid1.pqGrid( "setSelection", null );
        };



« Last Edit: June 07, 2016, 01:09:38 am by waldemarb »