We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Filter question

Is it possible to change the query type for a string column? I know that the docs say "Always `StartsWith` operator will be used for string filter"... but I've got a situation where it'd be very handy to use "Contains" rather than "StartsWith".

3 Replies

SA Saravanan Arunachalam Syncfusion Team May 2, 2017 08:35 AM UTC

Hi Brian, 
Thanks for contacting Syncfusion’s support. 
We have achived your requirement by using “create” event of Grid control. In the create event, we have bound the open event for the filter dialog and we have changed the item from the ejDropDownList by using selectItemByValue method in the open event. Please refer to the below code example and online documentation link. 
<ej-grid id="FlatGrid" allow-paging="true" allow-filtering="true" create="onCreate"> 
    <e-filter-settings filter-type="menu"></e-filter-settings> 
    . . . 
</ej-grid> 
<script type="text/javascript"> 
    function onCreate() { 
        if (this.model.allowFiltering && this.model.filterSettings.filterType == "menu") { 
            $("#" + this._id + "_" + "stringDlg").ejDialog({ 
                //bind the open event for the string filter dialog 
                open: function (args) { 
                    var drpobj = this.element.find(".e-dropdownlist").ejDropDownList("instance"); 
                    //changed as Contains rather than startsWith 
                    drpobj.selectItemByValue("Contains"); 
                } 
            }) 
        } 
    } 
</script> 
 
Regards, 
Saravanan A. 



RB R Brian Lindahl May 2, 2017 02:42 PM UTC

is this possible in the "filter bar" mode?


SA Saravanan Arunachalam Syncfusion Team May 3, 2017 05:54 AM UTC

Hi Brian, 
We have analyzed your requirement and achieved it by using filterBarTemplate feature of Grid control and please refer to the below code example. 
<ej-grid id="FlatGrid" datasource="ViewBag.dataSource" allow-paging="true" allow-filtering="true"> 
    . . . 
    <e-columns> 
        . . .  
        <e-column field="ShipCountry" header-text="Ship Country" filter-bar-template="@(new FilterBarTemplate() {Create="create", Read="read",Write="write" })"> 
 
        </e-column> 
    </e-columns> 
</ej-grid> 
<script type="text/javascript"> 
    function create(args) { 
        return "<input>"; 
    } 
    function write(args) { 
        //Bind the keyup event for the filterbar input element 
        args.element.bind("keyup", ej.proxy(args.column.filterBarTemplate.read, this, args)); 
    } 
    function read(args) { 
        //Filter the column with contains operator 
        this.filterColumn(args.column.field, "contains", args.element.val(), "and", true); 
    } 
</script> 
 
We have created a sample that can be downloaded from the below link, 
Regards, 
Saravanan A. 


Loader.
Live Chat Icon For mobile
Up arrow icon