3.0 beta 2

Cancel a row change? onCurrentRowChanging?

How can a row change by cancelled?

I have tried returning true/false/1 from the grid's onCurrentRowChanging event but to no avail.

Karl Thoroddsen
August 22,
Same thing...
Have tried returning "error" but no luck.
Ben
October 13,
There are no row changing events in 2.0.1 - I am planning to add them in the future, but its not ready yet.
Alex (ActiveWidgets)
October 13,
Alex,

onCurrentRowChanging is being called. At least in my 2.0.1 install.

Is it a pseudo event? I.e. not really being called during the actual changing of rows?



Karl Thoroddsen
October 13,
Oops, sorry - I was thinking about something different (i.e. row editing/validation). Please discard my comment.
Alex (ActiveWidgets)
October 13,
Is there a way of canceling the row change inside RowChanging?
Karl Thoroddsen
October 13,
The blue highlighted rows are 'selected' rows, not necessary the 'current' one. To cancel the selection movement you have to cancel onSelectedRowsChanging event or both onSelectedRowsChanging and onCurrentRowChanging.

// block rows below 5th :-)

obj.onCurrentRowChanging = function(row){
    if (row > 4) return 1;
}

obj.onSelectedRowsChanging = function(rows){
    if (rows[0] > 4) return 1;
}
Alex (ActiveWidgets)
October 13,
Thanks Alex.
Karl Thoroddsen
October 16,
Thanks!! i was going nuts over this!...
I'm using onCurrentRowChanging to validate an entire row (I'm in single-cell mode so I never have multiple rows selected -dont really have a use for onSelectedRowsChanging).
The problem with your solution is that your test runs twice. I'm sending error messages on validation, so they appear twice.

I noticed that onCurrentRowChanging is fired before onSelectedRowsChanging, so I tried to tweak it by using storing the result of the first validation (during onCurrentRowChanging), and just sending the same result onSelectedRowsChanging.

var validationResult = null;
grid.onCurrentRowChanging = function(row)
{
    validationResult = validateRow(row)
    return validationResult;
}

grid.onSelectedRowsChanging = function(rows)
{
    return validationResult;
}

function validateRow(row)
{
// I WANT THIS TO ONLY RUN ONCE
    return (row > 2) ? 1 : 0;
}


I seems to work so far, but I find it really inelegant.

I tried using flags so that only the first event to fire would run the test, but it doesn't work because the event order doesn't seem perfectly predictible (for example if I'm navigating with the keyboard or just clicking), so sometimes only one event fires, and that impacts the next events cycle.

Anyway... i'm not being very clear but if anyone understands and has ideas, i'm listening ;) ! Cheers.
Ben
October 16,
What worked for me Ben was to simply ignore the CurrentRow changes and use only SelectedRows.

function getSelection()
{
  if (grid.getSelectedRows().length > 0)
    return getSelectedRows()[0];
  return -1;
}


Seems to work fine.
Karl Thoroddsen
October 16,
grid.onSelectedRowsChanging = function(value)
{ 			
  if (somethingchanged() && value != 0) 
  {
    alert('Record has been modified.  Please Update or Cancel the changes');
    return 1;
  }
}
Karl Thoroddsen
October 16,
ok thanks, i'll try that.
Ben
October 17,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.