6 Answers, 1 is accepted
One suggestion would be showing confirm in OnCommand client event of radgrid instead of setting the ConfirmText for the column. You can chek for any condition and cancel the Delete command before showing the confirm window.
aspx:
<telerik:GridButtonColumn UniqueName="DeleteButtonColumn" text="Delete" CommandName="Delete"> |
</telerik:GridButtonColumn> |
javacript:
function OnCommand(sender, args) { |
if (args.get_commandName() == "Delete") { |
if (condition) { // Check for condition to cancel the event, before showing confirm |
args.set_cancel(true); // Cancel the event |
} |
if (!confirm('Do you really want to delete the record?')) { // Showing confirm |
args.set_cancel(true); // Cancel the event |
} |
} |
} |
Think differently :)
Shinu.
Nate
Thanks, all help is appreciated.
The suggestion that Shinu had provided relies on the fact that a delete command is fired. Is that the case in your scenario? Could you please clarify what is the idea behind the accessing of the keyCode? This might not be needed as the delete command can be fired from both a button click or pressing the enter key. Do you want to cancel the deleting of an item only when an enter key is pressed? Please elaborate more on the exact scenario so we could provide a more precise suggestion.
Regards,
Angel Petrov
Telerik
Dear Angel Petrov - I am a total noob helping to solve a weird little issue with the implementation of this Telerik control. It seems that the control is 'attached' (is this the right word?) to a field which gathers data - in this case, month and year. Our end user uses the control to enter a date and when pressing Enter, instead of the date being recorded, we receive the notice that the record is about to be deleted. ???
I'm under the impression that the control has to fire a delete command? Is this corrrect? Or can the control be assigned another command - such as "not delete" or "Save date in client file xyz on server abc", etc?
Any advice appreciated - be gentle. I'm a dullard at this stuff and am wrapping my head around it.
Hi Fred,
Generally this behavior appears when the keyboardboard navigation is enabled both for RadGrid and the controls in it. When the end user uses the keyboard keys to navigate and manage data, both RadGrid and the controls in it will listen to the keyboard events and the first catching the key takes the action.
This behavior is described in the Keyboard support
"If controls inside the grid use the same keys and combinations as the grid, and do not prevent (consume) the keydown event, you may get unexpected behavior. For example, rows may be changed in the batch edit mode while the user is attempting to navigate through a combo box list.
To prevent this, you can set the ClientSettings.AllowKeyboardNavigation property of the grid to false. Alternatively, use widgets and code that prevents the keyboard event propagation. For example, replace RadComboBox with RadDropDownList, which prevents the up and down arrows from propagating.
Whether a control should prevent the propagation of the keyboard events is a gray area and some controls may do that, while others do not. This is highly specific to each control and to each key."
This behavior could also be the result of having the delete button configured to listen for the Enter key. Whenever it's pressed, click the button.
Nevertheless, I've been playing around with different scenarios and I am unable to replicate the issue.
Here is what I have tried and it does not fire the delete command when the Enter key is pressed:
Grid Markup
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" Width="800px" OnNeedDataSource="RadGrid1_NeedDataSource">
<ClientSettings AllowKeyboardNavigation="true">
</ClientSettings>
<MasterTableView AutoGenerateColumns="true" DataKeyNames="OrderID">
<Columns>
<telerik:GridTemplateColumn HeaderText="Template Column">
<ItemTemplate>
<%# Eval("OrderDate") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="RadDatePicker1" runat="server" EnableKeyboardNavigation="true"></telerik:RadDatePicker>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridButtonColumn CommandName="Delete"></telerik:GridButtonColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
C# - Code Behind
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = Enumerable.Range(1, 5).Select(x => new
{
OrderID = x,
OrderDate = DateTime.Now.AddDays(x),
Freight = x * .1,
ShipName = "Name " + x,
ShipCountry = "Country " + x
});
}
It would be very helpful if you could share some more details on the current scenario, I will take a look and see what can be done to prevent that from happening.
See also:
- Grid - Keyboard Support
- Change keyboard navigation commands in RadGrid with Batch editing
- Prevent numeric value changing with Batch editing when using keyboard navigation with the arrow keys
Kind regards,
Attila Antal
Progress Telerik