Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add models-table-server-paginated component #62

Merged

Conversation

mydea
Copy link

@mydea mydea commented Mar 2, 2016

While models-table works great for certain amounts of data, it cannot work with server-side paginated data. In order to make this possible, I added a second component, models-table-server-paginated, which makes this scenario possible.

This component extends the base models-table component. For the end user, it can be used (nearly) the same:

{{models-table-server-paginated data=model columns=myColumns}}

It expects myData to be an ember-data query, eg:

model: function() {
  return this.store.query('my-model', {});
}

It will then take this query and extend it with pagination, sorting and filtering information. All other query parameters added in will remain untouched. Everything else works exactly the same - global filters, column filters etc. still use the same properties to control them. A few things to notice:

  • When using filterWithSelect for a column, you must use predefinedFilterOptions, because the automatic loading of possible filter values cannot work here.
  • There is a new optional field filteredBy for columns, which works much like sortedBy: if set, this field will be used as query parameter, otherwise it will use the propertyName.
  • Sorting will not use multipleColumnSorting, it will only sort by one column.
  • If you set sortedBy: false on a column, sorting will be disabled for this column.

There are a couple of things which can be configured to adapt to your API:

// The property on meta to load the pages count from.
metaPagesCountProperty: 'pagesCount',

// The property on meta to load the total item count from.
metaItemsCountProperty: 'itemsCount',

// The time to wait until new data is actually loaded.
// This can be tweaked to avoid making too many server requests.
debounceDataLoadTime: 500,

// The query parameters to use for server side filtering / querying.
filterQueryParameters: {
  globalFilter: 'search',
  sort: 'sort',
  sortDirection: 'sortDirection',
  page: 'page',
  pageSize: 'pageSize'
},

This default configuration would try to get the total page count from model.get('meta.pagesCount') and the total item count from model.get('meta.itemsCount'), and would then go on to build the following query:

columns: [
  {
    propertyName: 'name',
    filteredBy: 'model_name'
  }
]

// after searching globally for "searchtexthere" 
// and in the name column for "filterforname",
// and going to page 2,
// the following query would be built:
?page=2&pageSize=50&search=searchtexthere&sort=name&sortDirection=ASC&model_name=filterforname

onechiporenko pushed a commit that referenced this pull request Mar 2, 2016
Add models-table-server-paginated component
@onechiporenko onechiporenko merged commit b8d7b82 into onechiporenko:master Mar 2, 2016
@onechiporenko
Copy link
Owner

Wow! Great thanks, @mydea .

@progand
Copy link

progand commented May 13, 2016

@mydea Its great! Do you plan to make ember-data optional? It would be perfect to use it with custom data layer.

@Micke5
Copy link

Micke5 commented May 31, 2016

Hi @mydea!
I really like your solution. I'm implementing it atm and its going well : )
I wondering how to avoid making double request to the server. The first is make when the model is declared:
model: function() { return this.store.query('my-model', {}); }
and then in the
_loadData() { ... store.query(modelName, query).then((newData) => { set(this, 'filteredContent', newData); set(this, 'isLoading', false); });
Is it possible to remove one of the requests?

@mydea
Copy link
Author

mydea commented May 31, 2016

Hey - I had a check in place that avoided calling this on initial load. But since a few things changed in the underlying models-table, this might not work anymore - I will try to look into it soon :)

@Micke5
Copy link

Micke5 commented Jun 1, 2016

Sweet! I'm looking forward to it :)

@Micke5
Copy link

Micke5 commented Jun 2, 2016

@mydea my last problem now is the double requests, how did you do to stop the first one? Does it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants