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
close icon

Retrieving additional parameter - BatchUpdate

Hi there,

I have been trying to pass in additional parameter to batchupdate and datasource methods on a grid, but having difficulty so far achieving it.

Let's say there are list of Users and each user belongs to an Organisation (one to many relationship).  Based on query string parameter (organisation ID) I filter the users and show them on a grid.

//this works
 public ActionResult Users(int orgID)
        {...}

so far good

But I have issue retrieving the orgID within the datasource and batch update methods

On cshtml side I have something like this (I have been playing around with ClientSideEvents based on other threads on this forum but no luck)

Html.EJ().Grid<UserViewModel>("Grid")
        .Datasource(ds =>
            ds.URL("BatchUserDataSource")
            .BatchURL("BatchUserUpdate")
            .Adaptor(AdaptorType.UrlAdaptor))
.EditSettings(edit => { edit.AllowAdding().AllowEditing().EditMode(EditMode.Batch); })
        .ToolbarSettings(toolbar =>
        {
            toolbar.ShowToolbar().ToolbarItems(items =>
            {
                items.AddTool(ToolBarItems.Add);
                items.AddTool(ToolBarItems.Edit);
                items.AddTool(ToolBarItems.Update);
                items.AddTool(ToolBarItems.Cancel);
            });
        })
...

and on server side couple of methods (datasource and update methods).  This where the problem is I can't seem to set the organisationID

//need organisationID to filter
 public ActionResult BatchUserDataSource(DataManager dm, int organisationID)
        {
            
            ViewBag.dataSource = Users(organisationID)
            IEnumerable DataSource = ViewBag.dataSource;
            BatchDataResult result = new BatchDataResult();
            DataOperations obj = new DataOperations();
            if (dm.Skip != 0)
            {
                DataSource = obj.PerformSkip(DataSource, dm.Skip);
            }
            if (dm.Take != 0)
            {
                DataSource = obj.PerformTake(DataSource, dm.Take);
            }
            result.result = DataSource;
            result.count = Users(organisationID).Count;
            return Json(result, JsonRequestBehavior.AllowGet);
}


//need organisationID for newly added records as they initially won't have the relationship setup initially
 public ActionResult BatchUserUpdate(List<UserViewModel> changed,
            List<UserViewModel> added, List<UserViewModel> deleted, int organisationID)
        {

}

//just for reference
public class BatchDataResult
        {
            public IEnumerable result { get; set; }
            public int count { get; set; }
        }


If you could assist me on this that would be greatly appreciated.


Regards
Prasanth

3 Replies

SR Sellappandi Ramu Syncfusion Team December 7, 2015 12:45 PM UTC

Hi Prasanthan,

Thanks for contacting Syncfusion support.

By default we have the Query property in grid and we can pass the extra parameter by using appParams property in query.

We have created a sample based on your requirement and passed the OrganizationID as additional parameter.

Please refer to the code example and sample,

@{

    int id = 10002;

}

@(Html.EJ().Grid<object>("Grid")

         .Datasource(ds => ds.URL("/Home/DataSource").Adaptor("UrlAdaptor").BatchURL("/Home/Update"))

         .Query("new ej.Query().addParams('organisationID', " + "'" + id + "'" + ")")

         .AllowPaging()

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

         .ToolbarSettings(toolbar =>

         {

             toolbar.ShowToolbar().ToolbarItems(items =>

             {

                 items.AddTool(ToolBarItems.Add);

                 items.AddTool(ToolBarItems.Edit);

                items.AddTool(ToolBarItems.Delete);

                 items.AddTool(ToolBarItems.Update);

                 items.AddTool(ToolBarItems.Cancel);

             });

         })

         .Columns(col =>

        {

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

            col.Field("Freight").HeaderText("Freight").EditType(EditingType.Numeric).Format("{0:C}").TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("ShipCountry").HeaderText("Ship Country").Width(110).Add();


        })

[Controller]

public ActionResult DataSource(DataManager dm, int organisationID)

        {

            var DataSource = OrderRepository.GetAllRecords();

            DataResult result = new DataResult();

            result.result = DataSource.Skip(dm.Skip).Take(dm.Take).ToList();

            result.count = DataSource.Count();

            return Json(result, JsonRequestBehavior.AllowGet);
        }


Sample: http://www.syncfusion.com/downloads/support/forum/121325/ze/EJGrid_121325791379490

Output screen:



Regards,
Sellappandi R


PR Prasanth December 10, 2015 01:58 PM UTC

Hi Sellappandi,

Thanks for the reply and code, things are seems to be working now.

One final question (more of confirmation).  Instead of hard coding the id  I have used Request.QueryString to retrieve the ID, just wanted to if there are any concerns / issues with this approach.

Instead of 

@{

    int id = 10002;

}

Following

@{

    int id = int.Parse(Request.QueryString["xxxx"]);

}


Regards
Prasanthan



PK Prasanna Kumar Viswanathan Syncfusion Team December 11, 2015 09:38 AM UTC

Hi Prasanth,

Yes, you can use the Request.QueryString to retrieve the ID value, and will not face any issue with this approach.


Please find the code example, screenshot and sample:

@{

    int id = int.Parse(Request.QueryString["id"]);

}


@(Html.EJ().Grid<object>("Grid")

         .Datasource(ds => ds.URL("/Home/DataSource").Adaptor("UrlAdaptor").BatchURL("/Home/Update"))

         .Query("new ej.Query().addParams('organisationID', " + "'" + id + "'" + ")")

         .AllowPaging()

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

         .ToolbarSettings(toolbar =>

         {

             toolbar.ShowToolbar().ToolbarItems(items =>

             {

                 items.AddTool(ToolBarItems.Add);

                 items.AddTool(ToolBarItems.Edit);

                 items.AddTool(ToolBarItems.Delete);

                 items.AddTool(ToolBarItems.Update);

                 items.AddTool(ToolBarItems.Cancel);

             });

         })

         .Columns(col =>

        {

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

            col.Field("Freight").HeaderText("Freight").EditType(EditingType.Numeric).Format("{0:C}").TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("ShipCountry").HeaderText("Ship Country").Width(110).Add();


        })
)


Screenshot:





Sample: http://www.syncfusion.com/downloads/support/forum/121325/ze/EJGrid-920762012

Regards,
Prasanna Kumar N.S.V

Loader.
Live Chat Icon For mobile
Up arrow icon