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.
Unfortunately, activation email could not send to your email. Please try again.

Retrieving additional parameter - BatchUpdate

Thread ID:

Created:

Updated:

Platform:

Replies:

121325 Dec 1,2015 09:18 PM Dec 11,2015 04:38 AM ASP.NET MVC 3
loading
Tags: Grid
Prasanth
Asked On December 1, 2015 09:18 PM

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

Sellappandi Ramu [Syncfusion]
Replied On December 7, 2015 07:45 AM

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

Prasanth
Replied On December 10, 2015 08:58 AM

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


Prasanna Kumar Viswanathan [Syncfusion]
Replied On December 11, 2015 04:38 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;