Search code examples
javascriptbackgrid

Preset search term in backgrid.js filter


In the documentation of the ClientSideFilter I read the following:

Renders a search form with a text box, optionally with a placeholder and a preset value if supplied during initialization.

I can set a placeholder value during initialization, but how can a preset value be supplied? It is missing from the initialization parameters.

(I would like to be able to link directly to a filtered table so a preset value would come handy.)


Solution

  • I believe the preset value mentioned in the documentation refers to the value in the filter's input field.

    Initializing your filter with a value option, will render the field with that value.

    var filter = new Backgrid.Extension.ClientSideFilter({
      collection: collection,
      placeholder: "Search",
      value: "PRESET"
    });
    

    Edit: If you want to link to a filtered grid, you'll have to trigger a search for the filter to take effect. You can do that by calling the filter's search function after the filter has been rendered.