<ejs-grid id="Grid" allowPaging="true" allowFiltering="true" actionBegin="actionBegin" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<e-data-manager url="/home/UrlDatasource" batchUrl="/Home/BatchUpdate" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-filterSettings type="Excel"></e-grid-filterSettings>
...
</ejs-grid>
<script>
function actionBegin(args) {
if (args.requestType === "filterchoicerequest") {
var filterfields = [];
var objFilter = Object.keys(args.filterModel.existingPredicate);
for (var i = 0; i < objFilter.length; i++) {
filterfields.push(objFilter[i]);
}
filterfields.push(args.filterModel.options.field);
args.query.distincts = [];
args.query.select(filterfields); // Created the select query
}
}
</script> |
public IActionResult UrlDatasource([FromBody]DataManagerRequest dm)
{
IEnumerable DataSource = order;
DataOperations operation = new DataOperations();
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = operation.PerformSearching(DataSource, dm.Search); //Search
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
DataSource = operation.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<Orders>().Count();
if (dm.Select != null)
{
DataSource = operation.PerformSelect(DataSource, dm.Select); // Selected the columns value based on the filter request
DataSource = DataSource.Cast<dynamic>().Distinct().AsEnumerable(); // Get the distinct values from the selected column
}
if (dm.Skip != 0)
{
DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = operation.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
} |
|
|
<script>
function actionBegin(args){
if (args.requestType == "filterchoicerequest") {
// you can set filter choice count based on your needs , by default count 1000
args.filterchoicecount = 1500;
}
}
</script> |
|
...
namespace EJ2Grid.Controllers
{
public class HomeController : Controller
{
public static List<Orders> order = new List<Orders>();
...
public IActionResult UrlDatasource([FromBody]DataManagerRequest dm)
{
IEnumerable DataSource = MappingFunction (order);
DataOperations operation = new DataOperations();
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = operation.PerformSearching(DataSource, dm.Search); //Search
}
...
return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
}
private List<OrderViewModel> MappingFunction (List<Orders> lstOrders)
{
List<OrderViewModel> lstOrderViewModel = new List<OrderViewModel>();
lstOrderViewModel.AddRange(lstOrders.Select(x => new OrderViewModel { OrderID = x.OrderID, CustomerID = x.CustomerID }));
return lstOrderViewModel;
}
...
public class Orders //class with all columns properties
{
...
public int OrderID { get; set; }
public int EmployeeID { get; set; }
public string CustomerID { get; set; }
public string ShipCity { get; set; }
public string ShipName { get; set; }
}
public class OrderViewModel //class for only displaying columns property in the grid
{
public int OrderID { get; set; }
public string CustomerID { get; set; }
}
}
}
|