$(function () {
var dataManager =ej.DataManager({ url: "/Home/DataSource", adaptor: "UrlAdaptor"});
$("#Grid").ejGrid({
dataSource: dataManager,
. . .
allowFiltering:true,
filterSettings: { filterType: "menu", filteredColumns: [{ field: "OrderID", operator: "equal", value: 10249, matchcase: true }, { field: "EmployeeID", value: 6, operator: "greaterthanorequal" }] },
. . .
columns: [
. . .
]
});
});
<Controller>
[System.Web.Http.ActionName("ExcelExport")]
[AcceptVerbs("POST")]
public void ExcelExport()
{
string gridModel = System.Web.HttpContext.Current.Request.Params["GridModel"];
GridProperties gridPropert = ConvertGridObject(gridModel);
ExcelExport exp = new ExcelExport();
IEnumerable data = OrderRepository.GetAllRecords(); // Get datasource
exp.Export(gridPropert, (IEnumerable)data, "Export.xlsx", ExcelVersion.Excel2013, false, false,"none");
} |
<When refreshing the Grid>
var dataManager =ej.DataManager({ url: "/Home/DataSource", adaptor: "UrlAdaptor"});
$("#Grid").ejGrid({
dataSource: dataManager,
allowResizing: true,
allowPaging: true,
allowSorting: true,
allowReordering: true,
allowSelection: false,
enablePersistence: false,
allowTextWrap: true,
allowFiltering:true,
pageSettings: { pageSize: 10, pageCount: 10 },
toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.ExcelExport] },
toolbarClick:"toolbarClick",
}); //Now single request will send to server side
<Or>
//Refresh the datasource using setmodel
$("#Grid").ejGrid("option", { dataSource: ej.DataManager({ url: "/LoanApplicationQuery/List", adaptor: new ej.UrlAdaptor() }) })
|
$(function () {
var dataManager =ej.DataManager({ url: "/Home/DataSource", adaptor: "UrlAdaptor"});
var field = "OrderID";
var operator = "equal";
var value = 10249;
$("#Grid").ejGrid({
dataSource: dataManager,
. . .
filterSettings: { filterType: "menu", filteredColumns: [{ field: field, operator: operator, value: value }] },
. . .
columns: [
. . .
]
});
}); |
<style>
.e-grid .e-headercell .e-filtericon {
display:none;//Hide the filter icons from Grid
}
</style> |
var gridObj = $("#grid").ejGrid("instance");
//Pass operators & value as array
gridObj.filterColumn([{
field: "FundingDate",
operator: [ej.FilterOperators.greaterThanOrEqual, ej.FilterOperators.lessThanOrEqual],
value: [startDate, endDate],
predicate: "and"
}]);
|
System.NullReferenceException was unhandled by user code HResult=-2147467261 Message=Object reference not set to an instance of an object. Source=mscorlib StackTrace: at System.Object.GetType() at Syncfusion.Linq.EnumerableExtensions.GetElementType(IEnumerable source) at Syncfusion.JavaScript.DataSources.DataOperations.Execute(IEnumerable dataSource, GridProperties property) at Syncfusion.EJ.Export.GridExcelExport.ExecuteResult(GridProperties GridModel, Object dataSource) at Syncfusion.EJ.Export.GridExcelExport.ExportHelper(GridProperties gridModel, Object dataSource) at Syncfusion.EJ.Export.GridExcelExport.Export(GridProperties gridModel, Object dataSource, Boolean multipleExport) at CSC.Framework.Web.Infrastructure.QueryController`2.ExcelExport[TKey](IQueryable`1 dataQuery, String gridModel, IDictionary`2 sources, String exportFileName) in F:\Dev\hcs_fe_platform\CSC.Framework.Web\Infrastructure\QueryController.cs:line 119 at hcs_webapp.Controllers.SettlementEntryQueryController.Export(String GridModel, String fileName) in F:\Dev\hcs_fe_platform\hcs_webapp\Controllers\SettlementEntryQueryController.cs:line 68 at System.Web.Mvc.ActionMethodDispatcher.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() at Castle.Proxies.AsyncControllerActionInvokerProxy.EndInvokeActionMethod_callback(IAsyncResult asyncResult) at Castle.Proxies.Invocations.AsyncControllerActionInvoker_EndInvokeActionMethod.InvokeMethodOnTarget() at Castle.DynamicProxy.AbstractInvocation.Proceed() at Glimpse.Mvc.AlternateType.AsyncActionInvoker.EndInvokeActionMethod.NewImplementation(IAlternateMethodContext context) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Proxies.AsyncControllerActionInvokerProxy.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() InnerException: |
{ "allowPaging": true, "showColumnChooser": false, "gridLines": "both", "allowSorting": true, "showStackedHeader": false, "selectedRecords": [], "stackedHeaderRows": [], "allowFiltering": true, "allowMultipleExporting": false, "allowSelection": false, "allowGrouping": false, "showSummary": false, "allowResizing": true, "allowResizeToFit": false, "allowTextWrap": true, "allowCellMerging": false, "enablePersistence": false, "enableFocusout": false, "selectedRowIndex": -1, "allowSearching": false, "enableToolbarItems": false, "allowReordering": true, "allowRowDragAndDrop": false, "enableTouch": true, "columnLayout": "auto", "locale": "en-US{\"EmptyRecord\":\"No records to display\",\"GroupCaptionFormat\":\"{{:headerText}}: {{:key}} - {{:count}} \",\"GroupText\":\" item\",\"True\":\"true\",\"False\":\"false\"}", "allowMultiSorting": false, "exportToExcelAction": "ExportToExcel", "exportToWordAction": "ExportToWord", "exportToPdfAction": "ExportToPdf", "_groupingCollapsed": [], "selectionSettings": { "selectionMode": ["row"], "enableToggle": false, "cellSelectionMode": "flow" }, "resizeSettings": { "resizeMode": "nextcolumn" }, "groupSettings": { "showDropArea": true, "showToggleButton": false, "showGroupedColumn": true, "showUngroupButton": true, "enableDropAreaAutoSizing": true, "captionFormat": null, "groupedColumns": [] }, "contextMenuSettings": { "enableContextMenu": false, "contextMenuItems": ["Add Record", "Edit Record", "Delete Record", "Sort In Ascending Order", "Sort In Descending Order", "Next Page", "Last Page", "Previous Page", "First Page", "Save", "Cancel", "Grouping", "Ungrouping"], "customContextMenuItems": [], "subContextMenu": [], "disableDefaultItems": false }, "filterSettings": { "filterType": "menu", "filterBarMode": "immediate", "showFilterBarStatus": true, "statusBarWidth": 450, "showPredicate": false, "filteredColumns": [{ "field": "EntryDate", "operator": "greaterthanorequal", "value": "2016-07-01T04:00:00.000Z", "matchcase": false }, { "field": "EntryDate", "operator": "lessthanorequal", "value": "2016-08-01T03:59:59.999Z", "matchcase": false }], "enableInterDeterminateState": true, "maxFilterChoices": 1000, "enableCaseSensitivity": false, "immediateModeDelay": 1500, "enableComplexBlankFilter": true, "blankValue": "" }, "searchSettings": { "fields": [], "key": "", "operator": "contains", "ignoreCase": true }, "sortSettings": { "sortedColumns": [{ "field": "Id", "direction": "ascending" }] }, "toolbarSettings": { "showToolbar": true, "toolbarItems": ["excelExport"], "customToolbarItems": [] }, "minWidth": 0, "currentIndex": 0, "rowDropSettings": { "dropMapper": null, "dragMapper": null, "dropTargetID": null }, "scrollSettings": { "width": "auto", "height": 0, "enableTouchScroll": true, "allowVirtualScrolling": false, "virtualScrollMode": "normal", "frozenRows": 0, "frozenColumns": 0, "buttonSize": 18, "autoHide": false, "scrollerSize": 18, "scrollOneStepBy": 57, "enableVirtualization": false }, "textWrapSettings": { "wrapMode": "both" }, "summaryRows": [], "enableRTL": false, "enableAltRow": true, "childGrid": null, "keySettings": null, "mergeCellInfo": null, "create": null, "actionBegin": null, "actionComplete": null, "actionFailure": null, "beginEdit": null, "endEdit": null, "endAdd": null, "endDelete": null, "beforeBatchAdd": null, "beforeBatchSave": null, "beforeBatchDelete": null, "batchAdd": null, "batchDelete": null, "cellSave": null, "cellEdit": null, "resizeStart": null, "resizeEnd": null, "resized": null, "load": null, "destroy": null, "rowSelecting": null, "rowSelected": null, "cellSelecting": null, "cellSelected": null, "columnSelecting": null, "columnSelected": null, "columnDragStart": null, "columnDrag": null, "columnDrop": null, "dataBound": null, "recordClick": null, "recordDoubleClick": null, "templateRefresh": null, "rightClick": null, "detailsCollapse": null, "detailsExpand": null, "contextOpen": null, "contextClick": null, "columns": [{ "field": "EntryDate", "type": "date", "format": "{0:MM/dd/yyyy}", "headerText": "Date", "visible": true, "allowResizing": true, "textAlign": "left" }, { "field": "TransactionNumber", "type": "string", "headerText": "TRN", "visible": true, "allowResizing": true, "textAlign": "left" }, { "field": "Location", "type": "string", "headerText": "Location", "visible": true, "allowResizing": true, "textAlign": "left" }, { "field": "FirstName", "type": "string", "headerText": "Customer First Name", "visible": true, "allowResizing": true, "textAlign": "left" }, { "field": "LastName", "type": "string", "headerText": "Customer Last Name", "visible": true, "allowResizing": true, "textAlign": "left" }, { "field": "Amount", "type": "number", "format": "{0:c}", "headerText": "Amount Financed", "textAlign": "right", "visible": true, "allowResizing": true }, { "field": "ProductName", "type": "string", "headerText": "Product Name", "textAlign": "right", "visible": true, "allowResizing": true }, { "field": "DiscountRate", "type": "number", "format": "{0:p}", "headerText": "Discount", "textAlign": "right", "visible": true, "allowResizing": true }, { "field": "DiscountAmount", "type": "number", "format": "{0:c}", "headerText": "Discount Amount", "textAlign": "right", "visible": true, "allowResizing": true }, { "field": "NetAmount", "type": "number", "format": "{0:c}", "headerText": "Net Funded Amount", "textAlign": "right", "visible": true, "allowResizing": true }], "isResponsive": false, "enableResponsiveRow": false, "virtualLoading": null, "keyConfigs": { "focus": "e", "insertRecord": "45", "deleteRecord": "46", "editRecord": "113", "saveRequest": "13", "cancelRequest": "27", "nextPage": "34", "previousPage": "33", "lastPage": "ctrl+alt+34", "firstPage": "ctrl+alt+33", "nextPager": "alt+34", "previousPager": "alt+33", "firstCellSelection": "36", "lastCellSelection": "35", "firstRowSelection": "ctrl+36", "lastRowSelection": "ctrl+35", "upArrow": "38", "downArrow": "40", "rightArrow": "39", "leftArrow": "37", "moveCellRight": "9", "moveCellLeft": "shift+9", "selectedGroupExpand": "alt+40", "totalGroupExpand": "ctrl+40", "selectedGroupCollapse": "alt+38", "totalGroupCollapse": "ctrl+38", "multiSelectionByUpArrow": "shift+38", "multiSelectionByDownArrow": "shift+40" } } |
var gridObj = $("#Grid").ejGrid("instance");
. . .
//Pass operators & value as array
gridObj.filterColumn([{
field: "OrderDate",
operator: [ej.FilterOperators.greaterThanOrEqual, ej.FilterOperators.lessThanOrEqual],
value: [startDate, endDate],
predicate: ["and","and"]
}]);
}
|
Hi Venkatesh,
Hi Venkatesh,
Thanks for your inputs regarding multiple filter options. I work with Joel and we hit a couple more issues related to filtering and exporting:
- seems each item passed into the gridObj.filterColumn() generates individual calls to the datamanager url, appending additional filter each time. In the sample snippet here: http://jsplayground.syncfusion.com/ed20prfi a total of 4 server calls were made to the datamanager url. Once during the grid initialization, and 3 times more apparently because I passed 3 filter column items. Is there a way to prevent this duplicate server calls?
- Related to previous scenario, we wanted the grid to always load with an initial filter applied. Seems we cannot do this during initialization - $("#Grid").ejGrid(...). If there's no way for that, can we then suppress the grid from making that remote call to the datamanager url during initialization (i.e. ejGrid() call), so we can just have a single server call when the gridObj.filterColumn() gets executed?
- When doing export via ej.Grid.exportAll() call. Is there a way to hook a javascript callback when the exported file gets downloaded?
Thanks in advance for your help!Chris Joson
<Grid>
var dataManager =ej.DataManager({ url: "/Home/DataSource", adaptor: "UrlAdaptor"});
$("#Grid").ejGrid({
dataSource: dataManager, //window.gridData,
filterSettings: { //Initial filteredColumn to show initial filter
filterType: "menu", filteredColumns: [{
field: "OrderDate",
operator: "greaterthanorequal",
value: startDate,
predicate: "and"
}, {
field: "OrderDate",
operator: "lessthanorequal",
value: endDate,
predicate: "and"
}
, {
field: "EmployeeID",
operator: "greaterthanorequal",
value: 0,
predicate: "and"
},
{
field: "EmployeeID",
operator: "lessthanorequal",
value: 10,
predicate: "and"
}, {
field: "CustomerID",
operator: ej.FilterOperators.notEqual,
value: "VINET",
predicate: "and"
}]},
toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.ExcelExport] },
toolbarClick:"toolbarClick",
columns: [
. . .
],
});
});
|
function btnclick() {
var gridObj = $("#Grid").ejGrid("instance");
var datepickerobj1 = $("#datepicker1").ejDatePicker("instance");
var datepickerobj2 = $("#datepicker2").ejDatePicker("instance");
var startDate = datepickerobj1.model.value;
var endDate = datepickerobj2.model.value;
//Assign the filter queries as array
gridObj.model.filterSettings.filteredColumns = [{
field: "OrderDate",
operator: ej.FilterOperators.greaterThanOrEqual,
value: startDate,
predicate: "and"
},
{
field: "OrderDate",
operator: ej.FilterOperators.lessThanOrEqual,
value: endDate,
predicate: "and"
}
];
gridObj.refreshContent(); // Refresh the Grid content
}
|
<toolbar button click event>
function toolbarClick(args) {
this.exportGrid = this["export"];
if (args.itemName == "Excel Export") {
this.element.find(".e-gridtoolbar").ejToolbar("disableItemByID", "Grid_excelExport"); //Intially hide the export button
this.exportGrid('/Home/ExcelExport') //Call the export method
fileDownloading(); // Call the file downloading(customize) fucntion
args.cancel = true;
}
}
<Customized functions>
function fileDownloading() {
var gridObj = $("#Grid").ejGrid("instance");
fileDownloadCheckTimer = window.setInterval(function () {
var cookievalue = ej.cookie.get("done"); // get server side cookie value when appending in onActionExecuting method
console.log(cookievalue);
if (cookievalue == "done")
finishDownload(); // Call the finish download fucntion
}, 1000);
}
function finishDownload() {
window.clearInterval(fileDownloadCheckTimer); //Clear the interval
ej.cookie.set("done"); //clears this cookie value
var gridObj = $("#Grid").ejGrid("instance"); // Create a instance for Grid
gridObj.element.find(".e-gridtoolbar").ejToolbar("enableItemByID", "Grid_excelExport"); // enable Grid export button
}
<Controller code>
[System.Web.Http.ActionName("ExcelExport")]
[AcceptVerbs("POST")]
[CookieManage]
public void ExcelExport()
{
System.Web.HttpContext.Current.Session.Clear();
string gridModel = System.Web.HttpContext.Current.Request.Params["GridModel"];
GridProperties gridPropert = ConvertGridObject(gridModel);
ExcelExport exp = new ExcelExport();
IEnumerable data = OrderRepository.GetAllRecords(); // Get datasource
exp.Export(gridPropert, (IEnumerable)data, "Export.xlsx", ExcelVersion.Excel2013, false, false, "none");
}
<OnActionExecuting function>
public class CookieManage : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.HttpContext.Response.Cookies.Add(new HttpCookie("done", "done"));
base.OnActionExecuting(filterContext);
}
} |