<ejs-grid id="Grid" dataSource="ViewBag.datasource" allowPaging="true" height="365">
<e-grid-pagesettings pageSize="10"></e-grid-pagesettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
. . .
</e-grid-columns>
</ejs-grid>
|
public IActionResult UrlDatasource([FromBody]DataManagerRequest dm)
{
IQueryable<OrdersView> datasource = new NorthwindDataContext().OrdersViews;
QueryableOperation db = new QueryableOperation();
int count = datasource.Count();
if (dm.Where != null) // for filtering
datasource = db.PerformFiltering(datasource, dm.Where, dm.Where[0].Condition);
if (dm.Sorted != null)//for sorting
datasource = db.PerformSorting(datasource, dm.Sorted);
if (dm.Search != null)
datasource = db.PerformSearching(datasource, dm.Search);
if (dm.Skip >= 0)//for paging
datasource = db.PerformSkip(datasource, dm.Skip);
if (dm.Take > 0)//for paging
datasource = db.PerformTake(datasource, dm.Take);
return Json(new { result = datasource.ToList(), count = count });
} |
public void ConfigureServices(IServiceCollection services)
{
...
services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
} |
<input type="hidden" name="_ejRequestVerifyToken" value="f2cd20a3-5ae1-4e19-be61-d409191be3b1" />
<ejs-grid id="Grid" allowPaging="true" load="onLoad">
...
</ejs-grid>
<script>
function onLoad() {
var tokenValue = $("input[name=_ejRequestVerifyToken]").val();
this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': tokenValue }];
};
</script> |
|
Thank you for the solution.
I'm not able to send additional params to the asp.net core controller.
<ejs-grid id="audioFilesSearchGrid" load="onLoad"
allowPaging="true" allowSorting="true" allowFiltering="true" actionBegin="tagACustomModel">
<e-data-manager url="@Url.Action("GetSomeTiles", "Test")" adaptor="UrlAdaptor"></e-data-manager>
...
</ejs-grid>
I get an error about the query
Grid:
<ejs-grid id="Grid" allowPaging="true" actionBegin="actionBegin" >
</ejs-grid>
<script type="text/javascript">
function actionBegin(args) {
var grid = document.getElementById("Grid").ej2_instances[0];
grid.query.addParams('MyParameter', 'MyValue');
}
</script>
--------------------------------------------------------------------------------------------------------------------------
Controller:
public class HomeController : Controller
{
public static List<Orders> order = new List<Orders>();
public IActionResult Index()
{
return View();
}
public IActionResult UrlDatasource([FromBody]TestDm dm)
{
...
}
public class TestDm : DataManagerRequest
{
public string MyParameter { get; set; }
}
} |
|