BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Thank you. However, that only answers part of my question (note: I have a remote datasource in which the "select all" functionality on the client-side is not particularly useful).
If I filter data in the grid, I need to be able to pass the filtered result set back to a controller action.
I guess the more specific question would be how do I apply the filtering options to my server-side datasource using the GridProperties instance, similar to the export process?
Queries |
Response | |
“I have a remote datasource in which the "select all" functionality on the client-side is not particularly useful”
|
In knowledgeBase documentation we used local data in Grid. If we used local data in Grid we can get the whole data from the dataSource. If we bind remote dataSource then we can only get the current page of Grid. So, we suggest you to send the checkSelectedRowIndexes to server-side and get the selected records in server side.
| |
“If I filter data in the grid, I need to be able to pass the filtered result set back to a controller action.”
|
If you need the filtered data to the controller, use getFilteredRecords method of ejGrid. This method is used to get filtered record in Grid.
For more information, refer the below help document.
| |
“how do I apply the filtering options to my server-side datasource using the GridProperties instance”
|
For applying filtering options in server-side, use the below code example:
|
Thank you for your assistance.
1. I intend on using the checkSelectedRowIndexes, but I need the filtered result set first.
2. getFilteredRecords is a client-side method, with presumably the same drawbacks when using a remote data source (current page only)
3. You've misunderstood the filtering that I want to do on the server - I don't want to create a filter in the controller method. The filter settings need to originate on the client and be applied in the controller method. Please see below for what I want to accomplish.
In the DataOperations class, there is an Execute method that takes the unfiltered data source and a GridProperties instance. The GridProperties data source is what I need to get. The way this is done for the export process is below, but I cannot figure out how to do this for other controller methods.
To get the GridProperties instance for the export process:
string gridModel = System.Web.HttpContext.Current.Request.Params["GridModel"];
GridProperties gridProperty = ConvertGridObject(gridModel);
The ConvertGridObject is described here. The part that does not work is getting "GridModel" request parameter, as that request parameter does not exist. How can I pass this into the request?
Queries |
Response | |
“getFilteredRecords is a client-side method, with presumably the same drawbacks when using a remote data source (current page only)”
The filter settings need to originate on the client and be applied in the controller method. Please see below for what I want to accomplish.
|
Once we bind remote dataSource in Grid, we have loaded the Grid with only the paginated data as a load on demand concept. So, when we using getFilteredRecords is a client-side method we will get only the current page data.
In the attached sample we are using URL adaptor and we initiate the filterSettings in client-side. Once we define the filterSettings in Grid, the DataManager class helps in binding the Grid queries passed to the server-side. Based on those queries you can perform server-side operation on the Grid data.
The query parameters are serialized by the DataManager class and the server-side operations such as sorting, filtering, paging are performed by the PerformSorting, PerfomWherFilter, PerformSkip and PerformTake methods. In Server-side we able to get the whole data instead of current page.
Find the code example:
|
1. Any grid configuration with a remote data source will do. It must allow filtering, sorting, and multiselection.
2. I'm using the latest stable version 15.2.0.46.
3. With the aforementioned grid configuration, here is the scenario:
a. The user will sort and filter the grid.
b. The user will click a button that posts back to the controller. For example, say I have an "Assign" button that when clicked I want to take all of the records in the grid and assign them to a user. This operation must only be applied to the filtered, selected records across all pages. To accomplish this, I would want to make an ajax call to my controller's "Assign" method, passing in the results of checkSelectedRowIndexes. Within that controller method, I need to be able to obtain the GridProperties object based on the client filter and sort values set by the user (this should be very similar to how the GridProperties object is obtained when exporting, as I've already mentioned). With the GridProperties object, I should be able to call the DataOperations.Execute method with my IEnumerable data source and the GridProperties object. Presumably, this will provide me with the exact state of the grid on the client - filtered and sorted - as my working result set. Once I have that, I should be able to use the checkSelectedRowIndexes values to further filter my working result set to only those records that were selected. Once that is done, I can execute a method to perform the user assignment.
Again, the problem I am having is I cannot achieve this part. Please advise on how I can accomplish this.
<button id="buttonnormal"> Query </button>
<br />
<div id="Grid"></div>
<script type="text/javascript">
$(function () {
var dataManager = ej.DataManager({ url: "/Grid/Data", adaptor: new ej.UrlAdaptor() });
$("#buttonnormal").ejButton({
size: "mini",
showRoundedCorner: true,
click: "btnClick",
});
$("#Grid").ejGrid({
dataSource: dataManager,
-------------------
columns: [
-------------------------
]
});
});
function btnClick(args) {
var grid = $("#Grid").ejGrid("instance");
grid.model.dataSource = null;
grid.model.query = null;
$.ajax({
type: "POST",
url: "/Grid/DataSource",
data: { "model": JSON.stringify(grid.model) },
success: function (response) {
------
}
})
}
</script>
------------------------------------------------
public ActionResult DataSource(string model)
{
GridProperties gridModel = (GridProperties)Syncfusion.JavaScript.Utils.DeserializeToModel(typeof(GridProperties), model);
IEnumerable DataSource = OrderRepository.GetAllRecords().ToList();
DataOperations dp = new DataOperations();
IEnumerable FilteredData = dp.Execute(DataSource, gridModel);
return Json(model, JsonRequestBehavior.AllowGet);
} |
Thank you. That looks like exactly what I want to accomplish, but I am getting an exception during the deserialization method. I've attached my model string.
The exception is: "booleanedit is not a valid value for EditingType"
The exception seems to stem from the "columns" property of the grid and one of the column definitions (see below).
{"type":"checkbox","width":50,"clipMode":"ellipsiswithtooltip","tooltip":"{{:value}}","visible":true,"showInColumnChooser":true,"allowResizing":true,"field":"","textAlign":"center","allowSorting":false,"allowFiltering":false,"allowGrouping":false,"editType":"booleanedit"}
Please advise.
I've attached a workaround for the aforementioned defect. After getting past that issue, I ran into another issue with the checkSelectedRowsIndexes array and multiselect. Here is a playground link to see the issue: http://jsplayground.syncfusion.com/4hgxka4y
Scenario:
As of now, I have workarounds for any remaining issues and I am able to accomplish my original goal - with a remote data source, pass all selected records to the server and perform an operation on all of them.
Thank you for your assistance.