- Home
- Forum
- ASP.NET Core - EJ 2
- Filtering with additional external fields
Filtering with additional external fields
I could not find any examples on how to add extra fields that can be used in filtering remote data.
Filtering works with in-place filters in the header row of the data grid, but I want to add some extra fields as separate section on page.
Hi Marko Gluhak,
Greetings from Syncfusion support.
Upon reviewing your query, it appears that you are trying to filter the additional fields on your web page. In order to provide a solution, we kindly request further information to validate your requirements effectively.
- It seems that you wish to add extra fields as a separate section on a web page. Could you please confirm whether these additional fields need to be added to the existing Grid columns? If not, we would appreciate a more detailed explanation of your use case.
- “I could not find any examples on how to add extra fields that can be used in filtering remote data” – this line indicates that you are attempting to dynamically add columns to the Grid and to filter them accordingly. This can be achieved using the 'changeDataSource' method of the Grid. For more information, please refer to the documentation link provided below.
Documentation Link: how-to-change-the-data-source-or-columns-dynamically
- Furthermore, it appears that you are utilizing Remote Data Binding in the Grid. Therefore, we kindly request clarification on the adaptor details and the current version of the Syncfusion package you are using.
- Please elaborate on the scenarios in which you intend to add additional fields and in which case you need to send those additional field values to the backend.
Providing this information will enable us to better understand your requirements and offer a timely solution.
Regards
Aishwarya R
Hi.
here is example what I would like. I have student and enrollments. Each student can have many enrollments. I have grid that display all enrollments and column are:
- Firstname of student
- Lastname of student
- Date od enrollment
- Name of class
- Grade text (artificial column that is calculated on the fly on server, basically turn ids to text - this can not be used for filtering as data displayed are not part of columns in database
On that same page (above grid) I want to have search section that includes:
- Student city
- Student email
- Date of enrollment invitation
- Grade
- Button that will initiate grid refresh
<e-data-manager url="/Admin/AppUser/GetAppUsersGrid" crossdomain="true" adaptor="UrlAdaptor" ></e-data-manager>
......
I did manage to achieve this (I did not test all scenarios) but I'm not is is right way.
- I add text field "CountryNameSearch"
- I set the model for the .cshtml page with my own class "AppUserListSearchModel" which inherits "DataManagerRequest" and has "CountryNameSearch" property
- I changed the backend method signature to reflect that (public async Task<IActionResult> GetAppUsersGrid( [FromBody] AppUserListSearchModel dm ))
- I add actionBegin="actionBegin" to ejs-grid tag helper in .cshtml
- I add javascript part with:
function actionBegin(){
if (this.query.params.length && this.query.params.find(element => element.key === "CountryNameSearch"))
this.query.params["CountryNameSearch"].value = countryNameValue;
else
this.query.addParams("CountryNameSearch", countryNameValue);
}Hi Marko Gluhak,
Thank you for sharing the details.
Based on the information provided, it appears that you are attempting to apply filters to an external search area by disabling filtering within the Grid. You have also attempted to meet this requirement for a single field in the actionBegin event of the Grid. For filtering by multiple fields, we recommend generating complex predicates using which you can create composite filter criteria.
We have developed a simple sample where there are two input fields in the search area, with one field being a part of the Grid and the other not defined in the Grid columns. Searching for values in both input fields will result in the Grid displaying corresponding results.
In the onclick event of the search button, filter predicates have been created and assigned to the query property of the Grid. For further information, please consult the attached sample, video demonstration, and code example.
|
DataGridFeatures.cshtml
<div class="control-section"> <form id="customForm"> <div class="form-row"> <div class="form-group col-md-6"> <div class="e-float-input e-control-wrapper"> <input name='CustomerID' type='text' /> <span class="e-float-line"></span> <label class="e-float-text e-label-top">Customer Name</label> </div> </div> <div class="form-group col-md-6"> <div class="e-float-input e-control-wrapper"> <input name='ShipCountry' /> <span class="e-float-line"></span> <label class="e-float-text e-label-top">Ship Country</label> </div> </div> <div class="btnStyles"> <ejs-button id="search" onclick=processForm(event) content="Search"></ejs-button> <ejs-button id="clear" content="Clear"></ejs-button> </div> </div> </form> </div>
function processForm(event) { event.preventDefault(); var grid = document.getElementById('Grid').ej2_instances[0]; const form = document.getElementById('customForm'); const inputs = form.getElementsByTagName('input'); const predicates = []; for (let i = 0; i < inputs.length; i++) { const input = inputs[i]; if (input.value) { const field = input.name; const value = input.value; const predicate = new ej.data.Predicate(field, 'equal', value); predicates.push(predicate); } } const filterQuery = new ej.data.Query().where(ej.data.Predicate.and(predicates)); grid.query = filterQuery; }
|
Sample and Video demo: Attached.
If you need any further assistance or have additional questions, please feel free to let us know.
Documentation Link: Building-complex-filter-criteria-using-predicate
Regards
Aishwarya R
Attachment: 188411SampleAndVideo_e413a199.zip
- 4 Replies
- 2 Participants
-
MG Marko Gluhak
- May 25, 2024 01:56 PM UTC
- Jun 4, 2024 04:48 AM UTC