15
Views
2
Comments
Solved
[OutSystems Data Grid] OutSystems DataGrid - Accelerators/SearchData
outsystems-data-grid
Reactive icon
Forge asset by OutSystems
Application Type
Reactive
Service Studio Version
11.55.26 (Build 64206)

I am using the searchdata function from OutSystems DataGrid.

The returned result is not as per what I expected. For example, if I search for "Crane C", it will show result that contains either "Crane" or "C". But I actually wanted it to be "Crane C".

Example: 

Search for "Crane"

Search for "Crane C"

2022-11-12 11-28-30
Gonçalo Martins
Staff
Solution

Hi @Daus Shah 

After playing around with Wijmo FlexGrid APIs on their website, I managed to find a way (even though complex) to change the search algorithm.
The way to achieve that requires some complex custom JavaScript that I was able to simplify to the following:

- Add the following code in a JSNode in Grid’s OnInitialize event handler:

wijmo.grid.search.FlexGridSearch.prototype._applySearch = function () {  
    var e = this._g;  
    this._rxSrch = this._rxHilite = null;  
    var t = this.text.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');  
    if (t.length) {    
        var r = e && e.caseSensitiveSearch ? 'g' : 'gi';    
        this._rxSrch = new RegExp('(?=.*' + t + ')', r);    
        t = wijmo.escapeHtml(t);    
        this._rxHilite = new RegExp('(' + t + ')(?![^<]*>)', r);  
    }  
    var i = e ? e.collectionView : null;  
    i.sourceCollection && i.refresh && i.refresh();
};

// Being $parameters.GridWidgetId the Grid block identifier


- Here's the final result:
 

Hope it helps!

Cheers,
GM


2022-11-12 11-28-30
Gonçalo Martins
Staff

Hi @Daus Shah 

That's how the search mechanism from Wijmo Flexgrid works, so have you searched if they have a way to change the search criteria? If so, I can try to help once you share a way to do that directly in Wijmo Flexgrid.

Cheers,
GM

2022-11-12 11-28-30
Gonçalo Martins
Staff
Solution

Hi @Daus Shah 

After playing around with Wijmo FlexGrid APIs on their website, I managed to find a way (even though complex) to change the search algorithm.
The way to achieve that requires some complex custom JavaScript that I was able to simplify to the following:

- Add the following code in a JSNode in Grid’s OnInitialize event handler:

wijmo.grid.search.FlexGridSearch.prototype._applySearch = function () {  
    var e = this._g;  
    this._rxSrch = this._rxHilite = null;  
    var t = this.text.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');  
    if (t.length) {    
        var r = e && e.caseSensitiveSearch ? 'g' : 'gi';    
        this._rxSrch = new RegExp('(?=.*' + t + ')', r);    
        t = wijmo.escapeHtml(t);    
        this._rxHilite = new RegExp('(' + t + ')(?![^<]*>)', r);  
    }  
    var i = e ? e.collectionView : null;  
    i.sourceCollection && i.refresh && i.refresh();
};

// Being $parameters.GridWidgetId the Grid block identifier


- Here's the final result:
 

Hope it helps!

Cheers,
GM


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.