Author Topic: Copy data from one column to other column on button click  (Read 4218 times)

Sunny

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 59
    • View Profile
Copy data from one column to other column on button click
« on: August 06, 2015, 01:10:02 am »
Hi,

Is it possible with button click in toolbar, to copy/paste data(only cells that are not empty) from Column-A to other Column-B in the same grid? Appreciate if you have any demo regarding this.

Thanks.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Copy data from one column to other column on button click
« Reply #1 on: August 06, 2015, 07:35:25 am »
In the button click listener, get dataModel.data option, iterate over the rows and copy cells from one column to another.

var data = $(this).closest( ".pq-grid" ).pqGrid( "option", "dataModel.data" );
for ( var i = 0; i < data.length; i++ ){
  var rowData = data[ i ];
  var cellData = rowData[ dataIndx of column A ];
  if ( cellData != null ){
    rowData[ dataIndx of column B ] = cellData;
  }
}
« Last Edit: August 06, 2015, 07:39:39 am by paramquery »

Sunny

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 59
    • View Profile
Re: Copy data from one column to other column on button click
« Reply #2 on: August 06, 2015, 11:52:45 am »
Is there any other way, instead of iterating all the rows in the grid, as I am worried iterating all overs the rows might be time consuming.

Looking for some kind of batch operation, in which change event gets triggered(on button click) with the rowList having only the rows that got cells copied into ColumnB. As my grid is using auto save,I would like to send one ajax call to server to update the records that were copied instead of calling updateRow method for each row where cell has been copied.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Copy data from one column to other column on button click
« Reply #3 on: August 06, 2015, 01:19:50 pm »
This way of updating rows is the fastest way, however it doesn't take part in tracking, so it's not suitable method for you.

you can replace rowData[ dataIndx of column B ] = cellData; by updateRow() method if you want to make the changes integral part of tracking. Though it meets your 1st requirement (tracking ), it would lead to as many change events as the number of times the updateRow() method is called so it doesn't meet your 2nd requirement (single change event ).

As you want to make the whole operation a single transaction with a single change event, there is  a need for an appropriate method i.e., updateRows() method in the API.

updateRows() is being added in the API and would be available in the next version.

Sunny

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 59
    • View Profile
Re: Copy data from one column to other column on button click
« Reply #4 on: August 06, 2015, 01:56:44 pm »
Thank you for prompt reply. updateRows() makes sense, and it suits my usecase.

Is there any update on ETA for your next version, will it be in this week?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Copy data from one column to other column on button click
« Reply #5 on: September 04, 2015, 08:45:20 pm »
I just figured that there is an alternative way to copy one column to another in a single transaction / single change event.

Example to copy Revenues to Profits column: http://jsfiddle.net/ubbs0c3w/

Hope it helps.
« Last Edit: September 04, 2015, 08:49:15 pm by paramquery »

Sunny

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 59
    • View Profile
Re: Copy data from one column to other column on button click
« Reply #6 on: September 05, 2015, 02:28:05 am »
Thank you for the update on this. Much appreciated.

I already used logic like,while iterating over the rows,copy from one column to other, and later send the updated list of copied data to the server in one call.