I am using a grid which has approximately 20 columns.
Depending upon what the user is viewing there are some dynamic columns - which I either add or remove using the following:
The problem I am having is that the Excel Filter does not work for the newly added fields.
Here is the basic flow of the request:
// this function is called when the new data needs to be displayed in the grid
function loadBacktestGroupBacktestResults(id, backtestResultId) {
// go get the dynamic columns
$.ajax({
type: "GET",
dataType: "json",
url: settings.getAdditionalFieldsUrl,
data: {
type: "backtestResult",
id: id
},
success: function(result) {
var gridElement = settings.$backtestResultGrid;
var gridInstance = gridElement.ejGrid("instance");
var parameters = { type: "backtestResult", id: backtestResultId, numberOfTopResults: 0 }
var query = new ej.Query().addParams();
$.each(parameters,
function(key, value) {
query.addParams(key, value);
});
gridElement.ejGrid({ query: query });
// I have simplified the next few lines of code for this example to show at a high level what the logic does
var fieldsToAdd = [ { field: "fieldName1", allowEditing: false, headerText: "Dynamic Field 1" }, { field: "fieldName2", allowEditing: false, headerText: "Dynamic Field 2" } ];
var fieldsToRemove = // gets an array of column names to remove
if (fieldsToAdd.length > 0 || fieldsToRemove.length > 0) {
gridInstance.columns(fieldsToAdd, "add");
gridInstance.columns(fieldsToRemove, "remove");
// updating the fields will cause an update in the datasource so we don't need to refresh the content
}
else {
// refresh the grid content will will use the new parameters
gridInstance.refreshContent();
}
}
});
Here is the definition of the grid
@(Html.EJ().Grid<BacktestResultRow>("BacktestResultGrid")
.Datasource(ds => ds.URL(Url.BacktestResultsBatchDataSource()).BatchURL(Url.BacktestResultsBatchUpdate()).Adaptor(AdaptorType.UrlAdaptor)) .Query("new ej.Query().addParams('type','').addParams('id','0').addParams('numberOfTopResults','0')") .EditSettings(edit => { edit.AllowEditing().EditMode(EditMode.Batch); })
.AllowFiltering() .AllowPaging()
.AllowResizeToFit()
.AllowSelection()
.AllowScrolling()
.AllowSorting()
.AllowTextWrap()
.FilterSettings(filter => { filter.FilterType(FilterType.Excel); }) .IsResponsive()
.MinWidth(250)
.PageSettings(pg => pg.PageSize(10))
.SelectionType(SelectionType.Multiple)
.ScrollSettings(col => { col.Width("auto").Height("auto"); })
.ShowColumnChooser()
Thanks, Jeff