Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Implementing Server-Side Pagination Using Postgresql in Appsmith (Part 4 - Filtering)

Issue

As I was building my application, I realized that I needed to add server-side filtering to make it more user-friendly. To do this, I needed to provide a way for my users to select specific fields from the table and provide a filter value for those fields. I achieved this by using a select widget and an input widget, and updating the query to use their values. With this update, users are now able to filter by title and body without any issues.

Resolution

In this final part of the series, we learned how to implement server-side filtering in our application. We added a select widget to allow users to select specific fields and an input widget to provide a filter value for that field. Then, we updated our query to use both widgets and filter the data accordingly.

To implement server-side filtering using PostgreSQL, we disabled the default filtering functionality in the table widget and used the following query:

SELECT * FROM posts 
WHERE {{W_tableFilter.selectedOptionValue ?? 'title'}} ILIKE '{{'%' + ${W_tableFilter.selectedOptionValue ? W_tableFilterInput.text : Table1.searchText} + '%'}}' 
LIMIT {{Table1.pageSize}} 
OFFSET {{(Table1.pageNo - 1) * Table1.pageSize}};

In this query, W_tableFilter.selectedOptionValue refers to the currently selected field of the select widget and W_tableFilterInput.text refers to the input of the input widget. By using these widgets together, we can filter data on the server side and provide more efficient and accurate results.

Overall, implementing server-side filtering in Appsmith using PostgreSQL is a simple process that can greatly improve the performance and functionality of our applications.