Adding search or filter fields to your listing
Published: Tuesday, 08 April 2014 14:43
Any connection can have 1 search field and/or multiple filter fields, the search field can actually search multiple db fields, however, any filter field can be used to filter the results based on 1 db field value only.
Please also note that for any filter field to work, its value must match the value at the db field or the record, so if you want to filter records by the "first_name" field, then you will have to enter the exact field name in the filter field.
We are going to add 1 search field and 1 filter field to our listing, let's first go to the "Front list" tab under our connection's edit page.
Scroll down to the "filters" box and enter this:
Then enter this into the "Searchable" box:
In the code above, we are going to filter articles based on their status (published or not), and we are going to search their titles and/or ids.
Scroll up, please note that our "display type" is "Table", switch the tab to "List display", then select the "Table" area and let's add the code for our search and filter fields, in the "Header code" box, please add this code:
<input type="text" name="srch" placeholder="search...." class="form-control A" />
<input type="text" name="fltr[Article][status]" placeholder="1 or 0" class="form-control A" />
<input type="submit" name="submit" value="Submit" />
The fields names in the code above are very important, the filter field name should match the db field name you are trying to match.
Please note that in the code above, we could use a "dropdown" for the filter field, but we used a textbox for simplicity, and we had to use a "submit" button, in order to be able to submit the search/filter values, otherwise the data would not submit by pressing "Enter", if you don't like the button then simply hide it using CSS, but it must be there.
Save your connection and test the new feature!