We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Additional parameter to delete query (toolbar item)

Hello Syncfusion Team,
I'm using grid control with toolbar items.
On the delete operation, I want to send to controller an additional parameter.

Now, this is my controller:

public JsonResult Delete(int key){
   .....
}

which I want to transform to:

public JsonResult Delete(int key, string additional_key){
   .....
}

In the ToolbarClick event I tried with:

function toolbarClick(sender){
    if(  $(sender.target).hasClass('e-delete')  ){
        this.model.query.addParams('additional_key', 'myvalue');
    }
}

I tried with actionBegin event also.
They doesn't work.

I changed it in 
$("#mytable").ejGrid("model.query", new ej.Query().addParams('additional_key', 'myvalue'));

but it changes the SELECT query.

How can I solve this problem?

And, where I can find documentation for this? Your components are very interesting and I want to study it.

Thank you

3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team November 18, 2015 09:43 AM UTC

Hi Omar,

Instead of using the additional parameters, we suggest using the Headers of the ejDataManager. While performing delete action in the actionBegin event, add the required number of array of objects into Headers and retrieve them using the Request Object of the HttpRequestMessage. Please refer to the below code example and screenshot.

@(Html.EJ().Grid<MvcApplication66.OrdersView>("FlatGrid")

        .Datasource(ds => ds.URL("/Home/DataSource").UpdateURL("/Home/Update").RemoveURL("/Home/Delete").Adaptor(AdaptorType.UrlAdaptor))

        .AllowFiltering()

        .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })

        .ToolbarSettings(tools =>

                {

                    tools.ShowToolbar().ToolbarItems(items =>

                    {

                         . . . .

                        items.AddTool(ToolBarItems.Delete);

                    }

                        );

                })

        .ClientSideEvents(events => { events.ActionBegin("begin").ActionComplete("complete"); })

        .Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

            . .  . . .

        }))

<script>

    function begin(args) {

        if (args.requestType == 'delete') {

            args.model.dataSource.dataSource.headers = [];

            args.model.dataSource.dataSource.headers.push({ " additional_key": " myvalue" })

        }

    }

    function complete(args) {

        if (args.requestType == 'delete') args.model.dataSource.dataSource.headers = [];//to avoid headers value to be interfered with other actions, emptied the Headers  

    }



</script>

[codeBehind]

public ActionResult Delete(int key)

        {

            var obj = Request.Headers.GetValues("additional_key")[0];

            var data = OrderRepository.GetAllRecords();

            return Json(data, JsonRequestBehavior.AllowGet);
        }




Refer to the following Help Documents for APIs and User Guides.

http://help.syncfusion.com/js/api/ejgrid

http://help.syncfusion.com/aspnetmvc/grid/getting-started

Regards,
Seeni Sakthi Kumar S.


OM Omar Muscatello November 24, 2015 08:54 AM UTC

Thank you very much Seeni Sakthi Kumar Seeni Raj.


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team November 25, 2015 04:39 AM UTC

Hi Omar,
 
We are happy to hear that your issue has been resolved.
 
Get back to us if you need further assistance.
 
Regards,
 
Seeni Sakthi Kumar S.

Loader.
Up arrow icon