Material-table: Remote data fetching on every search/filter keystroke

Created on 26 Aug 2020  路  3Comments  路  Source: mbrn/material-table

When implementing the example for remote data and doing a search, it sends the query for every keystroke in the search or any filter input

Is there a way to set a timer for to wait after a keystroke before trickering the query for remote data?

question wontfix

Most helpful comment

You can set the debounceInterval within in the options attribute of the MaterialTable Component.

<MaterialTable
    options={{...this.options, debounceInterval: 1000}}
    .
    .
    .

All 3 comments

You can use JS Debouncing technique to tackle that.

function debounce(func, wait, immediate) {
    var timeout;
    return function() {
        var context = this, args = arguments;
        var later = function() {
            timeout = null;
            if (!immediate) func.apply(context, args);
        };
        var callNow = immediate && !timeout;
        clearTimeout(timeout);
        timeout = setTimeout(later, wait);
        if (callNow) func.apply(context, args);
    };
};

and then fire this on KEYUP event for the search box.


var myEfficientFn = debounce(function() {
    // All the taxing stuff you do, after 2 seconds
}, 2000);

<inputFieldREF>.addEventListener('keyup', myEfficientFn);

You can set the debounceInterval within in the options attribute of the MaterialTable Component.

<MaterialTable
    options={{...this.options, debounceInterval: 1000}}
    .
    .
    .

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bohrsty picture bohrsty  路  3Comments

kfirshahar picture kfirshahar  路  3Comments

jlgreene2 picture jlgreene2  路  3Comments

victorwvieira picture victorwvieira  路  3Comments

balibou picture balibou  路  3Comments