Removing fields from OData searching

I have been altering an existing grid to allow paging from the server.  I have integrated OData v3 into our WebAPI and am able to retrieve data back from the server that populates the grid.  This grid is also using the search toolbar.  I have some fields that I do not want to search.  They are constructed on the front end and don't have an OData counterpart on the back-end.  In addition to this, on is the hidden ID field.  OData attempts to call tolower on this (and the other field doesn't exist), so errors occur.  When I remove the columns, everything works fine.

Is there a way to exclude these columns from the search tool?

Thanks!

3 Replies

GL Gowri Loganathan Syncfusion Team March 27, 2020 09:17 AM UTC

Hi Brandt Horrocks , 
 
Thanks for contacting Syncfusion Forum. 
 
Query : Is there a way to exclude the columns from the search tool? 
 
From your query we understood that you want to exclude some columns in your search tool while perform searching. The fields property of searchSettings enables the desired columns to be available in search tool while searching. In the below code snippet we exclude the CustomerID column and store the other columns in array which needs to be in search tool and assign it to the fields property of searchSettings inside the dataBound event of Grid. Like that you can exclude the desired column to perform searching operation. Kindly refer to the below code snippets. 
 
Code snippet 
 
 
 
. . . .  
 
@(Html.EJ().Grid<object>("FlatGrid") 
              . . . .  
            .AllowSearching() 
 
            .ClientSideEvents(eve => { eve.DataBound("dataBound"); }) 
            .ToolbarSettings(toolbar => 
            { 
             toolbar.ShowToolbar().ToolbarItems(items => 
            { 
              items.AddTool(ToolBarItems.Search); 
            }); 
            }) 
            . . . . . .  
 
<script type='text/javascript'> 
 
    var col = [];  // create an empty array to store the searchable columns 
 
    function dataBound(args) {  // triggers when data bind to grid 
         
       for (i = 0; i < args.model.columns.length; i++) { 
 
            if (args.model.columns[i].field != "CustomerID") {    // check the condition for non-searchable column 
 
                col.push(args.model.columns[i].field);     // push all the searchable columns to variable 
            } 
        } 
        this.option({ searchSettings: { fields: col } })   // enable searching with the required columns here 
 
    } 
</script> 
 
 
 
Also refer the below API link: 
 
 
We also would like to let you know about our next generation JavaScript product - Essential JS 2, in case if you are not aware of it. Essential JS 2 is fully re-written to be modular, responsive and lightweight.     
      
We suggest you look into our following product page for more details.     
      
Demo page for ej2 Grid     
 
Please get back to us if you need further assistance 
 
Regards, 
Gowri V L. 



BH Brandt Horrocks March 27, 2020 03:32 PM UTC

Thank you, that was helpful.  Because my column fields are static and I am using EJ1 (Javascript), It was sufficient for my just to specify the searchSettings.fields attribute:

searchSettings: { fields: ["Name", "ShortName", "Source", "Description"] },


GL Gowri Loganathan Syncfusion Team March 30, 2020 05:24 AM UTC

Hi Brandt Horrocks, 
 
Thanks for the update. 
 
Please get back to us, if you need more assistance  
 
Regards, 
Gowri V L. 


Loader.
Up arrow icon