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.
Syncfusion Feedback

How can I filter the grid when the datasource is set with URL

Thread ID:

Created:

Updated:

Platform:

Replies:

129418 Mar 16,2017 11:41 AM UTC Mar 21,2017 06:01 AM UTC ASP.NET MVC 3
loading
Tags: Grid
Cornel Amarandei
Asked On March 16, 2017 11:41 AM UTC

Hi,
I have a grid like this:
@(Html.EJ().Grid("JobsGrid")
.AllowPaging()
//.ToolbarSettings(toolbar => { toolbar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.Search); }); })
.AllowFiltering()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().ShowDeleteConfirmDialog(); })
.Columns(col =>
{
col.Field("Id").HeaderText("ID").IsPrimaryKey(true).Visible(false).Add();
col.Field("Title").HeaderText("Name").ValidationRules(v => v.AddRule("required", true)).Width(300).Add();
col.Field("ExternalId").HeaderText("External Id").TextAlign(TextAlign.Right).Add();
col.Field("JobTypeId").HeaderText("Job Type").ValidationRules(v => v.AddRule("required", true)).Width(150).ForeignKeyField("JobTypeId").ForeignKeyValue("Name").DataSource(ViewBag.JobTypes).Add();
col.Field("ADP").HeaderText("ADP").TextAlign(TextAlign.Right).Add();
col.Field("Deadline").HeaderText("Deadline").TextAlign(TextAlign.Right).Add();
col.Field("ActualHours").HeaderText("Actual").TextAlign(TextAlign.Right).Add();
col.Field("PlannedHours").HeaderText("Planned").TextAlign(TextAlign.Right).AllowEditing(false).Add();
col.Field("TotalHours").HeaderText("Total").TextAlign(TextAlign.Right).AllowEditing(false).Add();
col.Field("OrderedHours").HeaderText("Ordered").TextAlign(TextAlign.Right).Add();
col.Field("Color").HeaderText("Color").ValidationRules(v => v.AddRule("required", true)).Width(75).Add();
})
.Datasource(ds => ds.URL("Jobs/GetData").UpdateURL("Jobs/Update").InsertURL("Jobs/Insert").RemoveURL("Jobs/Delete").Adaptor(AdaptorType.UrlAdaptor))
.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);
});
})
)
And the action Jobs/GetData looks like this:
public JsonResult GetData(DataManager dm)
{
var result = new DataResult();
var jobs = new List();
var operation = new DataOperations();
var today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
foreach (var job in db.Jobs.Include(j => j.EmployeeJobs).ToList())
{
decimal planned = 0;
foreach(var employeeJobs in job.EmployeeJobs)
{
planned += (decimal)Utils.IntersactionWeekDays(today, DateTime.MaxValue, employeeJobs.StartTime, employeeJobs.EndTime) * 8;
}
jobs.Add(new JobModel()
{
Id = job.Id,
Title = job.Title,
ExternalId = job.ExternalId,
JobTypeId = job.JobTypeId,
ADP = job.ADP,
Deadline = job.Deadline,
ActualHours = job.ActualHours,
OrderedHours = job.OrderedHours,
Color = job.Color,
PlannedHours = planned,
TotalHours = job.ActualHours + 0
});
}
result.result = jobs;
result.count = jobs.Count();
if (dm.Skip > 0)
result.result = operation.PerformSkip(result.result, dm.Skip);
if (dm.Take > 0)
result.result = operation.PerformTake(result.result, dm.Take);
return Json(result, JsonRequestBehavior.AllowGet);
}
How can I make the filtering working in this case? Please note that I'm using Entity Framework.
Regards,
Cornel.

Thavasianand Sankaranarayanan [Syncfusion]
Replied On March 17, 2017 03:32 PM UTC

Hi Cornel, 
 
Thanks for contacting Syncfusion support. 
 
Query: How can I make filtering in the Url Adaptor enabled in Grid. 
 
We have analyzed your query and based on your requirement we suggest you to handle the filtering in the server side itself. 
 
While using UrlAdaptor, you can handle grid operation (paging/filtering/searching/sorting) in server side. When performing paging, filtering, sorting, editing operations on the grid queries are passed to the server side using DataManager class and using DataOperations class methods you perform server-side operations. 
 
Refer the below code example. 
 
 
@(Html.EJ().Grid<OrdersView>("FlatGrid")   
              .Datasource(ds => ds.URL("/Grid/DataSource").Adaptor(AdaptorType.UrlAdaptor))   
   …   
   
public ActionResult DataSource(DataManager dm)   
        {   
            IEnumerable DataSource = new NorthwindDataContext().OrdersViews.ToList();   
            DataResult result = new DataResult();   
            DataOperations operation = new DataOperations();   
            result.result = DataSource;   
            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting   
            {   
                result.result = operation.PerformSorting(DataSource, dm.Sorted);   
            }   
            if (dm.Where != null && dm.Where.Count > 0) //Filtering   
            {   
                result.result = operation.PerformWhereFilter(DataSource, dm.Where, dm.Where[0].Operator);   
            }   
            result.count = result.result.AsQueryable().Count();   
            if (dm.Skip > 0)   
                result.result = operation.PerformSkip(result.result, dm.Skip);   
            if (dm.Take > 0)   
                result.result = operation.PerformTake(result.result, dm.Take);   
            return Json(result, JsonRequestBehavior.AllowGet);   
        }   
 
 
We have prepared a sample and it can be downloadable from the below location. 
 
 
Refer the following knowledge base 
 
 
Refer the help documentation. 
 
 
Regards, 
Thavasianand S. 


Cornel Amarandei
Replied On March 20, 2017 12:34 PM UTC

Hi Thavasianand,

Thanks for your information. It worked.

Regards,
Cornel.

Thavasianand Sankaranarayanan [Syncfusion]
Replied On March 21, 2017 06:01 AM UTC

Hi Cornel, 

We are happy that the problem has been solved. 
 
Please get back to us if you need any further assistance.  
 
Regards, 
Thavasianand S. 


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.

Warning Icon 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.Close Icon

;