Permalink
Browse files

fix(datatable): Allow override populate and fix search bug

  • Loading branch information...
RWOverdijk committed Jun 24, 2016
1 parent f540e2a commit 5b4f0f5fb15da9afa375c9d33418f4cf1f3a945f
Showing with 22 additions and 9 deletions.
  1. +22 −9 src/datatable.js
@@ -9,20 +9,21 @@ import {Statham} from "json-statham";
@inject(Router, Element, EntityManager)
export class DataTable {
@bindable({defaultBindingMode: bindingMode.twoWay})
criteria = {populate: null};
criteria = {};
@bindable({defaultBindingMode: bindingMode.twoWay})
where = {};
@bindable limit = 30;
@bindable columns = '';
@bindable searchColumn = 'name';
@bindable searchable = null; // Show the search field? (Optional attribute).
@bindable sortable = null; // Columns can be sorted? (Optional attribute).
@bindable edit = null; // Rows are editable? (Optional attribute).
@bindable destroy = null; // Rows are removable? (Optional attribute).
@bindable page = 1; // Current page.
@bindable select; // User provided callback, called upon clicking on a row.
@bindable searchable = null; // Show the search field? (Optional attribute).
@bindable sortable = null; // Columns can be sorted? (Optional attribute).
@bindable edit = null; // Rows are editable? (Optional attribute).
@bindable destroy = null; // Rows are removable? (Optional attribute).
@bindable page = 1; // Current page.
@bindable populate = false; // Which columns to populate. True for all, string for specific.
@bindable select; // User provided callback, called upon clicking on a row.
@bindable repository;
@bindable data;
@bindable route;
@@ -62,6 +63,12 @@ export class DataTable {
this.criteria.skip = this.page * this.limit - this.limit;
this.criteria.limit = this.limit;
if (!this.populate) {
this.criteria.populate = null;
} else if (typeof this.criteria.populate === 'string') {
this.criteria.populate = this.populate;
}
this.repository.find(this.criteria, true).then(result => {
this.data = result;
}).catch(error => {
@@ -106,12 +113,18 @@ export class DataTable {
this.load();
}
searchColumnChanged() {
searchColumnChanged(newValue, oldValue) {
delete this.criteria.where[oldValue];
return this.doSearch();
}
doSearch() {
this.criteria.where = {[this.searchColumn]: {contains: this.search}};
if (typeof this.criteria.where[this.searchColumn] === 'object') {
this.criteria.where[this.searchColumn].contains = this.search;
} else {
this.criteria.where[this.searchColumn] = {contains: this.search};
}
if (!this.ready) {
return;

0 comments on commit 5b4f0f5

Please sign in to comment.