Calling the ItemCommand Handler from JavaScript

Reid

I am trying to get a confirmation dialog working when the user hit's "Update" button in a MasterEditTemplateForm template of a RadGrid. The scenerio is working fine in all other respects. I have followed the appropriate links, have the JavaScript in an external file and a container div working correctly that displays the dialog to the user.

I can step into the JavaScript code and verify that OpenConfirm() dialog shows the correct message to the user, and can also verify that the return result is true or false based on the Ok or Cancel buttons clicked.

How can I fire the Grid's ItemCommand handler if the result of the dialog was yes?

The ItemCommand handler would normally validate the data entry and then call a boolean function to either insert or update data. The result of that function closes or does not close the MasterEditTemplate form.

I need to integrate the confirmation dialog into the project. Any suggestions would be appreciated.

Reid

Hi Princy, this looks like it would work but makes no distinction with respect to whether the Grid is in Edit or Insert Mode, in other words should the confirmCallBackFn() use "PerformInsert" or "Update"? Is there another built in JavaScript method to establish this?

Reid

The attachment uses LINQ to load data from a APP_DATA folder demonstrating the Telerik SessionDataSource class (handy, thank you) but I do not see anything related to detecting insert/edit mode, forgive me if I am missing something.

Reid

The "Update" button in the MasterEditTemplate of the RadGrid when clicked shows the RadWindow confirmation dialog in the div to the user and the correct response via the OpenConfirm() function is passed to the argument of the confirmCallBackFn() function.

The radGrid variable is not null and the fireCommand functions can be called.

The case below that fires the "Update", indeed fires the ItemCommandHandler with the correct "RadGrid.UpdateCommandName" constant.

Questions

ItemIndex parameter As you can see below I am passing the ItemIndex arg as "0" (to test)

Determining Insert or Update state when firing the fireCommand() function. Still no way to determine what state the grid is in, Edit or Insert) I do not want to expand the JS to include an additional param for the state (actually just the button caption) but would rather abstract that processing to the JS to inherently cover future scenarios.

Reid

Waiting for the Telerik team to return Monday I have been investigating and experimenting. My solution is working but the ItemCommand always contains the MasterTable as the e.Item.OwnerTableView.Name coming into the event handler in the code behind.

I created a new JavaScript function that the button object in the markup below can call passing in itself as an additional parameter. This way I can determine if the record is in "Update" or "Insert" mode. ( again I would prefer not to do it this way )

[Stack]
at System.Web.UI.ControlCollection.AddAt(Int32 index, Control child)
at Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated)

ASPX:

<ClientSettings>

<ClientEvents OnGridCreated="GridCreated"/>

</ClientSettings

But this works if I place it in the external .js file:

function GridCreated(sender, args) {

radGrid = sender;

}

And as a result the "confirmCallBackFn" callback has access to it when the radconfirm() function is called.

So my questions are :

Do you know why the page cannot find the grid using "$find"?

Why after firing the JavaScript function "fireCommand()" on the *detail* table does the ItemCommand always contains the MasterTable as the e.Item.OwnerTableView.Name coming into the event handler in the code behind instead of the nested detail table's name?

Reid

Ok, thanks for that, now the code placed in the ASPX page works, how much I benefit from that over everything in the external .js file I do not know. I do not need to include the button now to query the edit state of the grid.

But again, the problem is as in my last post .... Please answer this question for the 3rd time in this forum, why is the ItemCommand handler in the CS code seeing the e.CommandName as the MasterTableView and *NOT* the embedded detail table?

Yavor

Based on the supplied information, it is hard to determine what is causing the issue with the command name. To further investigate it, please open a formal support ticket, and send us a small project, demonstrating your setup and code logic.
We will debug it locally, and get back to you with additional information.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Reid

I wanted to follow up and complete this thread with the details of what was needed to get this going.

First of all here is the JavaScript code that fires the command against the correct GridTableView :

function confirmCallBackFn(arg) {

if (arg == true) {

var editIndexCount = radGrid._editIndexes.length;

var detailTablesArray = radGrid.get_detailTables();

var detailTable = detailTablesArray[3];

// We are either in Update or Insert mode

if (editIndexCount > 0)

{

detailTable.fireCommand("UpdateFoodMenuItem");

}

else

{

detailTable.fireCommand("InsertFoodMenuItem");

}

}

}

Now why that works and the code in the above post (Feb 1st) did not, where I iterated though the detail tables to fire the event I am not sure. In my previous post the code behind handler was only being called for the root or primary GridTableView (MasterTableView). Using the JavaScript above it works with the understanding that you have to use a "Custom" parameter, in my case "UpdateFoodMenuItem".

While I am thankful for the support I got from Telerik on this, I would like to format a generic JS script to detect the active GridTableView. As you can see the index of the GridTableView is hard coded, I would make sense to abstract that from the call.

When i click the UpdateAll button i do get the "Do you want to save." confirm message and i also check that it does go inside the if condition in "confirmCallBackFn(arg)" button for some reason it doesnt call the ItemCommand event handler of "rdgEduDetail".

Iana Tsolova

Try clearing the edited items using the below code for instance. Note that you will need to rebind the grid afterwards:

RadGrid1.EditIndexes.Clear();

RadGrid1.Rebind();

Greetings,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

Amarendra Parab

I have a Support ID:282304 in which speaks about the same issue but with more information and have also replied on what you had suggested to that ticket, that was prior to this reply on this thread. Please refer that support ticket and go through my reply where i have added more information of what is exactly happening.

As far as your reply for this thread goes, i have already done e.Edit = false( e is the GridCommandEventArgs of ItemCommand event) which is equivalent to removing the item from the EditIndexes.Clear() method. Also after doing e.Edit = False i am doing a Rebind() on the RADGrid.

I tried the suggestion you gave but it is not working.

Please give you suggestion on the Support id : 282304, so that we have only one follow up on this issue.

Thanks,

Amarendra

Iana Tsolova

Thank you for opening a support ticket. I will check it out and write you back there.

Greetings,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

RBarnes

I know this is an old thread, but was/is there a resolve for this issue discussed here?

I was able to add a custom command and work around the issue, but the below is still an issue with firecommand on a DetailTable is issued.

Why after firing the JavaScript function "fireCommand()" on the *detail* table does the ItemCommand always contains the MasterTable as the e.Item.OwnerTableView.Name coming into the event handler in the code behind instead of the nested detail table's name?

If the behavior remains, you can pass a custom argument as the second parameter and use it on the code-behind to get the name of the real table view.

Regards,
Eyup
Telerik

Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items

Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.