esvit/ng-table — pull request #235 by chexxor (2014-03-07 18:13:09+00:00)
Title: Make getData and reload return promises.

#### Summary

Make the `getData`, `getGroups`, and `reload` functions return promises which contain the table's data.

An implication of this change is that new implementations of these methods by users can return data to the table in one of two ways:

1) Return a promise which contains the data (new way)
2) Resolve the Deferred object (old way)

This is backwards-compatible, and can be called a new feature.

#### Motivation

I have a multi-view app. The main view is a table of items and details, using ng-table, and a secondary view uses the same items, but displays related records. Because I use the table's data in two places, it needs to be stored in a service. I am storing the entire "ngTableParams" object in a service, then using it the controllers of both views.

In my secondary view, I get the table data, then query related records from a database. This `getData` operation is asynchronous, so it needs to return a promise. Here's a summary of what I need to do:

// ***** Secondary View ***** //
// If the Search Table hasn't been displayed, the `panelTableParams.data`
// property won't be populated, so we need to manually invoke it.
var searchPanels = panelTableParams.data;
var hasSearchPanels = searchPanels && searchPanels.length > 0;
var pSearchPanels = $q.when(hasSearchPanels ? searchPanels : panelTableParams.reload());
var pPanelBookings = pSearchPanels
.then(function(searchPanels) {
var panelIds = _.pluck(searchPanels, 'Id');
// (query and return related records)
})

Currently, ngTable's `reload` function returns nothing, so I can't get the table's data after telling it to reload, because my `getData` function is asynchronous.

#### Solution

Change the `getData`, `getGroups`, and `reload` functions to return a promise of the table's data, where they were returning nothing before.

Thoughts?