cloudflarearchive / backgrid-select-all

Select-all extension for Backgrid.js
http://backgridjs.com
MIT License
12 stars 31 forks source link

Please add Backgrid.getCountSelectedModels() #11

Closed jeffreycahyono closed 8 years ago

jeffreycahyono commented 10 years ago

It would be useful for this extension to have Backgrid.getCountSelectedModels() to retieve the number of selected models,

The use case is like the Gmail UI button, where certain toolbar button is displayed only when there are some row selected. The toolbar listens to backgrid:select event and retrieve Backgrid.getCountSelectedModels(). If the result is bigger than zero the groups of toolbar shown

pmaidens commented 10 years ago

An easy way to do this is by using Backgrid.getSelectedModels().length That will give you the length of the array returned by getSelectedModels() which should be equal to the number of selected rows.

jeffreycahyono commented 10 years ago

Yes I know, but the implementatin of getSelectedModel iterate selectAllHeaderCell.selectedModels which is not efficient if called repeteadly. It would be more efficient if the getCountSelecetedModels() can directly retrieve selectAllHeaderCell.selectedModels.length instead

wyuenho commented 8 years ago

There isn't a way to know for sure whether a model had been selected without checking to see if it's in a collection, so just return the length of selectedModels won't work.