Hi Robert,
Thanks a lot! It worked for me!
You saved lots of time and efforts of mine!
I just changed it a bit. The initial code for splitting data into 2D
array was not working so I changed it to below and it worked. Giving
complete function so that someone else can directly refer it if
needed:
function OnBeforePasteInFlightGrid(eventArgs)
{
var rowValues = eventArgs.data.split("\n");
var values = new Array(rowValues.length-1);
var columnCount = rowValues[0].split(" ").length;
for(var i=0; i<= rowValues.length-2; i++)
{
values[i] = new Array(columnCount);
}
for(var p=0; p<= rowValues.length-2; p++)
{
var cellValues = rowValues[p].split(" ");
for(var q=0; q<= cellValues.length-1; q++)
{
values[p][q] =cellValues[q].trim();
}
}
var gridName = "FlightGrid";
var coords = eventArgs.getCoords();
var topX = coords.top.x;
var bottomX = topX + columnCount;
var topY = coords.top.y;
var bottomY = topY + values.length;
var tmpCell = null;
var tmpSource = null;
var tmpOldValue = null;
var tmpNewValue = null;
var tmpEventArgs = null;
var rowCounter = 0;
var columnCounter = 0;
//iterate over all rows
for (var row = topY; row < bottomY; row++)
{
//iterate over all fields
for (var column = topX; column < bottomX; column++)
{
//get the current cellObject with the row/column
counter
tmpCell = nitobi.getGrid(gridName).getCellObject(row,
column);
//get the grid datasource
tmpSource = nitobi.getGrid(gridName).getDataSource();
//get the old value from the current cell
tmpOldValue = nitobi.getGrid(gridName).getCellValue
(row,column);
//get the new value from the data array we prepared in
the beginning
tmpNewValue = values[rowCounter][columnCounter];
//construct a OnCellValidateEventArgs object with this
values
tmpEventArgs = new nitobi.grid.OnCellValidateEventArgs
(tmpSource,tmpCell, tmpNewValue,tmpOldValue);
//evaluate the eventMethod from the current column and
fire it with the created eventArgs
var result = nitobi.event.evaluate
(tmpCell.getColumnObject().getOnCellValidateEvent(),tmpEventArgs);
//increment the counter (for the prepared data array)
columnCounter++;
if(!result) return false;
}
columnCounter = 0;
//increment the counter (for the prepared data array)
rowCounter++;
}
return true;
}
Regards,
Mangesh Gurav