Counting the number of specific items in a table's column

If I have a column of status’, how could I get a count of each status? If the table is altered via filter, I need the new counts for each status value. This will help me update charts based solely on the displayed table.

If there is a better way to update charts based solely on the items currently displayed in the table, that would help, too.

Status Column

status pie chart


Currently, I would recommend you to add a CollectionChangeListener to your data source and generate a DataProvider containing a proper data. For example:

customersDs.addCollectionChangeListener(e -> {
	List<DataItem> items = customersDs.getItems().stream()
			.collect(Collectors.groupingBy(Customer::getGrade, Collectors.counting()))
			.map(entry -> new MapDataItem(ParamsMap.of("grade", entry.getKey(), "count", entry.getValue())))

	DataProvider dataProvider = new ListDataProvider(items);

I’ve prepared a demo project on GitHub.


This isn’t working in some ways, because MapDataItem is deprecated. For instance, I can’t get the key or value from the DataItem without errors being thrown.

I tried using the code above and it worked, but I couldn’t get the rest of my pie chart functionality to work with it. Plus, because some of the recommended code will be irrelevant soon, I’m not sure if this was the best choice.

I’ve attached some files that show my current process (which works great for now), but gets the data from the database instead of the table. It also uses deprecated code. This will show you how I’m also using the chart listeners to update the table from chart interactions. When a slice is removed from the whole, the table loses the pulled out items.

The recommended code created the chart, fine, but I couldn’t create PieChartValues from the MapDatItems, and using DataItems instead of PieChartValues didn’t work either.

Chart (2.7K)


You’re rigth is deprecated, but in my sample I use which is not.

Take a look at that probably will fit your needs. But it’s hard to guess without a sample project.