<label>Filter CustomerID Column:</label>
<input type="text" id="GridCustomerIDFilter"> @*text box*@
@*filter operators*@
@Html.EJ().DropDownList("FilterOperators").TargetID("Operators").WatermarkText("Select a Operator")
<div id="Operators">
<ul>
<li>equal</li>
. .
</ul>
</div>
@Html.EJ().Button("btn").Text("Filter").ClientSideEvents(events => events.Click("onClick"))
@(Html.EJ().Grid<object>("Grid")
.Datasource((IEnumerable<object>)ViewBag.data)
.AllowPaging()
.AllowFiltering()
. . .
. . .
)
<script>
function onClick(args) {
var gridObj = $("#Grid").ejGrid("instance");
var dropObj = $("#FilterOperators").ejDropDownList("instance");
var val = dropObj.getValue();
if (val == "clearfiltering")
gridObj.clearFiltering();
else
gridObj.filterColumn("CustomerID", val, $("#GridCustomerIDFilter").val());
}
</script>
|
Good day
Regarding the programmatic filtering of the javascript grid we are able to filter as indicated:
gridObj.filterColumn("CustomerID", val, $("#GridCustomerIDFilter").val());
Setting this however does not update the grid's ui to reflect this filter.
How can this be achieved?
Please see the following link for reference of what we are trying to achieve:
https://www.syncfusion.com/kb/6312/how-to-store-retrieve-grid-model-values-into-from-database
Good day
Thank you for your reply. I need to explain more in what I am trying to achieve.
We are using the excel filtering functionality of the grid. We set filter criteria by using the grid's UI filtering functionality. We then get these filtered values by using the following code:
let grid: ej.Grid = $("#grid").ejGrid("instance");
var state = {
filteredCol: grid.model.filterSettings.filteredColumns.slice()
}
var object = JSON.stringify(state); //converting object to string
alert(JSON.stringify(object));
We can then clear the filters and set the previous filters by using the following code:
var gridObj: ej.Grid = $("#grid").ejGrid("instance");
var obj = JSON.parse(data);
gridObj.model.filterSettings.filteredColumns = obj.filteredCol;
if (obj.cols)
gridObj.columns(obj.cols);
else
gridObj.refreshContent();//Refresh the Grid to apply the saved settings
When we set the filters programatically the UI of the grid does not update to show the filters we set.
How can this be achieved? Kindly advise.
Thank you for your feedback. Unfortunately it still doesn't work.
Step 1: Change the grid to enable excel filtering: filterSettings : { filterType : "excel" }
Step 2: Create a filter on the EmployeeID to show ids between 1 and 5. The EmployeeID of the grid now shows that it has a filter on the column. When you open the excel filter menu the Number Filters is ticked and the popup menu shows between as ticked. When clicking on between you see the filter as previously set.
Step 3: You can now save this filter.
Step 4: Now we can clear the filter.
Step 5: Now we can apply the saved filter. This applies the filter to the grid which is correct. BUT IT DOES NOT UPDATE the excel menu of the EmployeeID column to show that there is a number filter of BETWEEN applied to this column. As previously explained the EXCEL UI filter does not update the column.
Please find screenshots attached. I hope it is now clear what we are trying to do.
On a side note: Guys, the communication is not great and we are frustrated that it takes 3 times to explain what we are trying to do. Even in our previous support request we explicitly stated that we use Excel filtering but your example does not portray this. We need to improve here please.
function applyState(args) {
var gridObj = $("#PersistenceGrid").ejGrid("instance");
var obj = $('#list').ejDropDownList("instance");
var value = obj.model.value;
//Post the saved (in ejDropDownlist) time
//To retrieve the Grid objects
$.ajax({
type: "POST",
url: "/Home/Restate",
data: { "dropObject": value },
success: function (data) {
var obj = JSON.parse(data);
gridObj.model.filterSettings.filteredColumns = obj.filterCol;
gridObj.refreshContent();//Refresh the Grid to apply the saved settings
//update filter collection to cFilteredCols
var filterCols = gridObj.filterColumnCollection, fcol = [];
for(var c = 0; c < filterCols.length; c++) {
fcol.push(filterCols[c].field);
}
gridObj._excelFilter.cFilteredCols = fcol;
//refresh the header to update the icons
gridObj.refreshHeader();
},
});
} |
Thank you. This is working. Unfortunately I do not find the filterColumnCollection property in your documentation nor the API. How would we do this in TypeScript as there is no gridObj.filterColumnCollection?
We are defining the grid as follows:
var gridObj: ej.Grid = $("#grid").ejGrid("instance");
var filterCols = gridObj.filterColumnCollection, fcol = []; // This line does not work.
Kindly advise.