This is a migrated thread and some comments may be shown as answers.

OnColumnMoving event

1 Answer 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Polina
Top achievements
Rank 1
Polina asked on 24 Nov 2008, 10:31 PM
I have few questions regarding usage of the client side OnColumnMooving..() events.
1.
I would like to cancel column moving event if certain condition occurred (using ReorderColumnsOnClient="true")
for example here is my js method that cancels the event for first 2 columns in the grid.
function ColumnMoving(sender, eventArgs)
{     
    if(eventArgs.get_gridColumn().get_element().cellIndex < 2)
    {
        eventArgs.set_cancel(true);
    }
}
But what i find is when an event is canceled once, it never fires again for any of the other column.

2. Is it possible to use this event when  ReorderColumnsOnClient is set to "false"?

3. How can I find out the destination index of the column that is being reordered(meaning where is it about to be moved)?

Thank you
Polina

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 28 Nov 2008, 09:52 AM
Hello Polina,

I will answer in the same order of your questions.
  1. The problem is that you should check if the column index is smaller than 3, because the first visible column has index 1, not 0. In my local test I found that the event doesn't stop to fire itself after it is cancelled. Please review this article as well - OnColumnSwapping.
  2. Yes you can use set_cancel(...) method when specifying ReorderColumnsOnClient = false, but you have to set EnableViewState to false, too.Then Rebind the grid every time when the page post backs. Additionally, examine this topic for Reordering columns with viewstate disabled.
  3. You can find which the index of the target column is. Just use this method : eventArgs.get_gridTargetColumn().get_element().cellIndex;                                                              This will return the index of the target column. The method is explained in OnColumnSwapping article.
For your convenience I attached my test project.

Best regards,
Georgi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Polina
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or