The "smart" table model provides a superset of the simple table model's capabilities, and adds several key features:
- Views. Every smart model has a base "unfiltered" view containing all the rows that have been added to the table. You can define arbitrary new views by specifying filter functions that take rowdata and return
true(row should be included in view) orfalse(row should be excluded from view). The smart model maintains these views automatically as you add and remove rows. - Indices. The smart model can maintain indices that allow you to find particular table rows very quickly. Suppose, for example, that you have a column that contains a unique ID for each row. You can add this column as an index; the smart model will then maintain the index as rows are added and removed. Once you've added an index to the model, you can call the
locatemethod to quickly find any row from its index value. - Incremental Updating. The smart model automatically maintains model properties like sorting, filtering, and indices across table modifications. So you rarely need to explicitly re-sort the table, apply filters, etc. This also means that switching between views is essentially instantaneous.
- Indexed Selection. Index support allows the smart model to track which rows are selected by index value, and to therefore preserve the selection across sort, filter, add, and remove operations. For example, if you add an index for an ID column, you can tell the smart model to preserve the selection by ID. Then – regardless of how the rows move around on the screen – the smart model will ensure that the rows with these IDs are selected.
- Scalable Algorithms. The smart model uses algorithms that scale well as the table size grows, and includes optimizations specifically for huge tables. For example, the smart model merges in added rows as in a merge sort, rather then running repeated insertions. And the smart model looks for common cases that can be handled quickly: for example, if all added rows go at the beginning or end of the table, the smart model will save time by using native JavaScript push/shift operations.
- Backwards Compatibility. The smart model is backwards compatible with the Simple model: it adds parameters to existing methods and uses sensible defaults when these parameters are omitted. This means that you should be able to drop it in anywhere you currently use the Simple model.
- Comprehensive Unit Tests. The smart model includes a set of companion unit tests to ensure the code works properly and can be relied on for mission-critical tasks.
