Author Topic: Batch Editing and Change Log  (Read 4038 times)

TonyLeech

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 76
    • View Profile
Batch Editing and Change Log
« on: May 05, 2016, 05:32:21 pm »
I'm using your Batch Editing example, but using local data instead of remote.

When I change entries in cells the 'Undo' and 'Redo' work fine so it appears that the changes are correctly tracked.  But when I press 'Get Changes' all the arrays in the console are just empty (0 length).

If I use the 'Add Button' that works fine and I can see the addList array has entries.

Also if I copy and paste data from Excel and it automatically adds new rows to the bottom of the grid then the addList array also has entries.

Why do you think I just get empty array for update/change cells even though the change tracking appears to be on and working?

I've tried changing getChanges format to 'raw' and null but neither make a difference.

I have a number column used as a recIndx like this...

   var colM = [
      { title: "", maxWidth: 30, dataIndx: "num", dataType: "number", align:"center", editable: false, hidden: false, copy: true, cls: 'ui-state-default',
         render: function( ui ){
            return "" + (1 + $("#grid_php").pqGrid('getRowIndx',{rowData: ui.rowData}).rowIndx);
         }      
      },

and...
      dataModel: { recIndx: "num", data: data },

and I use your GetChanges button from your example like this...

            { type: 'button', icon: 'ui-icon-cart', label: 'Get Changes', cls: 'changes', listener:
               { "click": function (evt, ui) {
                  var changes = grid.getChanges({ format: 'byVal' });
                  try {
                     console.log(changes);
                  }
                  catch (ex) { }
                  alert("Please see the log of changes in your browser console.");
               }
               },
               options: { disabled: true }
            },

Why are my change arrays in the console always empty?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Batch Editing and Change Log
« Reply #1 on: May 05, 2016, 06:56:44 pm »
There seems to be a problem with recIndx in your case. recIndx is supposed to contain unique values for different records.

column.render callback is used for presentation, it doesn't make any changes in the data.

So you need to fill unique values in the "num" column.

TonyLeech

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 76
    • View Profile
Re: Batch Editing and Change Log
« Reply #2 on: May 05, 2016, 09:21:57 pm »
Yes, through trial and error I found the same thing...

The 'num' column that I'm using for recIndx was originally empty and being rendered automatically to appear like an incrementing row number.  This means that the recIndx cannot work with this column.  I copied the autoincrement render from another forum post/reply that I found here.

Can you tell me how I would automatically add an actual number to the column so that it can be used for recIndx?  This would need to add/update the column whenever data is pasted in from Excel.

I tried using my 'partnumber' colum as the recIndx instead which worked ok when I typed changes into the cells...and I got the arrays from getChanges.  But when I pasted cells that I'd copied from Excel these changes were not available from getChanges and again returned 0 length.

TonyLeech

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 76
    • View Profile
Re: Batch Editing and Change Log
« Reply #3 on: May 05, 2016, 09:29:46 pm »
* UPDATE *

If I initialise the 'num' column with values 1-10 I get 10 empty grid rows to use for recIndx and gives a nice space for my users to paste into.  That seems to work quite well and gives update arrays when contents are pasted in, and addList array if the pasted rows are more than 10 rows (the grid automatically expands to accept the extra rows).  But the update rows have a red triangle and the addList rows don't.  Can I switch off the red triangle from the update rows so that all rows look the same?

But I don't think the extra rows are filling numbers into my 'num' column.  So I would still be interested how to automatically add digits to my 'num' column when additional rows are pasted in.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Batch Editing and Change Log
« Reply #4 on: May 06, 2016, 11:35:06 am »
Code: [Select]
I don't think the extra rows are filling numbers into my 'num' column.  So I would still be interested how to automatically add digits to my 'num' column when additional rows are pasted in.

In batch editing, primary keys are auto filled when user clicks on save changes button and the records are committed. If you want to auto fill them instantly without any user intervention, you should check the instant editing demo.

I've created a demo for you with local data: http://jsfiddle.net/sedgnw8x/ and auto incrementing by using global variable.

I hope it helps you to understand the basic concepts, though I don't see much practical application for using local data in real life use cases.

you should link it with remote data as databases have functionality to auto generate unique values.

In Batch editing demo, the changes ( additions, updates and deletes ) are send to the remote server when save changes button is clicked. Server generates the unique values for the primary key column and send them back.

In success callback,  commit method is called which adds unique values to the new rows.

Code: [Select]
grid.commit({ type: 'add', rows: changes.addList });

http://paramquery.com/pro/api#method-commit
« Last Edit: May 06, 2016, 12:33:18 pm by paramquery »