Category: How do I do X?

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.

Get sum of a table column in a label


I need to calculate the total of a specific column in a label in my Appsmith application. I am using a table widget with client-side pagination. When I change the page, I want the label to update with the page-wise total dynamically. I also need the label to update when I apply sorting or filters from the client-side.


If you want to calculate the total of a specific column in a label in your Appsmith application table, there are different solutions depending on your implementation.

For server-side pagination, you can write a query to do this. For client-side pagination, you can use the lodash sumBy function to sum the data.

For example, if you want to sum the Visa column in your table, you can use the following code:
{{ _.sumBy(Table1.tableData, (row) => row.Visa) }}

If you want to get page-wise totals, you can use the following code if you are using client-side pagination:
{{_.sumBy(Table1.tableData.slice(Table1.pageOffset, Table1.pageOffset + Table1.pageSize), (row) => row.amount)}}
This will give you the sum of the amount column only for the current page.

If you want the sum to update dynamically when you apply sorting or filtering from the client-side, the previous code should work for you as it will recalculate the sum every time the data in the table changes.