Commit 9647c913 by kevalbhatt

ATLAS-3668 : UI: Sorting not working as expected for all the table

parent 97ecfc7e
......@@ -113,7 +113,7 @@ define(['require',
/** BaseCollection's Static Attributes */
{
// Static functions
getTableCols: function(cols, collection) {
getTableCols: function(cols, collection, defaultSortDirection) {
var retCols = _.map(cols, function(v, k, l) {
var defaults = collection.constructor.tableCols[k];
if (!defaults) {
......@@ -121,7 +121,8 @@ define(['require',
defaults = {};
}
return _.extend({
'name': k
'name': k,
direction: defaultSortDirection ? defaultSortDirection : null,
}, defaults, v);
});
return retCols;
......
......@@ -55,7 +55,10 @@ define(['require', 'utils/Utils', 'marionette', 'backgrid', 'asBreadcrumbs', 'jq
return this.charAt(0).toUpperCase() + this.slice(1);
}
/*
* Overriding default sortType
*/
Backgrid.Column.prototype.defaults.sortType = "toggle";
/*
* Overriding Cell for adding custom className to Cell i.e <td>
......
......@@ -149,6 +149,20 @@ define(['require',
includeAtlasTableSorting: false,
showDefaultTableSorted: false,
/**
* [updateFullCollectionManually If collection was updated using silent true
* then need to update FullCollection Manually for correct sorting experience]
* @type {Boolean}
*/
updateFullCollectionManually: false,
sortOpts: {
sortColumn: "name",
sortDirection: "ascending"
},
/** ui events hash */
events: function() {
......@@ -183,26 +197,29 @@ define(['require',
initialize: function(options) {
this.limit = 25;
this.offset = 0;
_.extend(this, _.omit(options, 'gridOpts', 'atlasPaginationOpts'));
_.extend(this, _.omit(options, 'gridOpts', 'sortOpts', 'atlasPaginationOpts'));
_.extend(this, options.atlasPaginationOpts);
_.extend(this.gridOpts, options.gridOpts, { collection: this.collection, columns: this.columns });
_.extend(this.sortOpts, options.sortOpts);
if (this.includeAtlasTableSorting) {
var oldSortingRef = this.collection.setSorting;
this.collection.setSorting = function() {
this.state.pageSize = this.length
var val = oldSortingRef.apply(this, arguments);
val.fullCollection.models.sort();
val.fullCollection.sort();
this.comparator = function(next, previous, data) {
var getValue = function(options) {
var next = options.next,
previous = options.previous,
order = options.order;
if (order === -1) {
return next < previous ? -1 : 1;
if (next === previous) {
return null;
} else {
return next < previous ? 1 : -1;
if (order === -1) {
return next < previous ? -1 : 1;
} else {
return next < previous ? 1 : -1;
}
}
}
if (val.state && (!_.isNull(val.state.sortKey))) {
......@@ -263,11 +280,14 @@ define(['require',
removeCellDirection function - removes "ascending" and "descending"
which in turn removes chevrons from every 'sortable' header-cells*/
this.listenTo(this.collection, "backgrid:sorted", function(column, direction, collection) {
// backgrid:sorted fullCollection trigger required for icon chage
this.collection.fullCollection.trigger("backgrid:sorted", column, direction, collection)
if (this.includeAtlasTableSorting && this.updateFullCollectionManually) {
this.collection.fullCollection.reset(collection.toJSON(), { silent: true });
}
}, this);
this.listenTo(this, "grid:refresh", function() {
if (this.grid) {
this.grid.collection.fullCollection.reset(this.collection.entities, { silent: true });
this.grid.trigger("backgrid:refresh");
}
});
......@@ -337,8 +357,13 @@ define(['require',
this.grid = new Backgrid.Grid(this.gridOpts).on('backgrid:rendered', function() {
that.trigger('backgrid:manual:rendered', this)
});
this.rTableList.show(this.grid);
if (this.showDefaultTableSorted) {
this.grid.render();
this.grid.sort(this.sortOpts.sortColumn, this.sortOpts.sortDirection);
this.rTableList.show(this.grid);
} else {
this.rTableList.show(this.grid);
}
},
onShow: function() {
if (this.includeSizeAbleColumns) {
......
......@@ -255,6 +255,8 @@ define(['require',
includeSizeAbleColumns: false,
includeTableLoader: false,
includeAtlasTableSorting: true,
showDefaultTableSorted: true,
updateFullCollectionManually: true,
columnOpts: {
opts: {
initialColumnsVisible: null,
......@@ -436,9 +438,8 @@ define(['require',
attributeObject: dataOrCollection.entities,
referredEntities: dataOrCollection.referredEntities
});
that.searchCollection.referredEntities = dataOrCollection.referredEntities;
that.searchCollection.entities = dataOrCollection.entities;
that.searchCollection.reset(dataOrCollection.entities, { silent: true });
that.searchCollection.fullCollection.reset(dataOrCollection.entities, { silent: true });
}
......
......@@ -116,7 +116,7 @@ define(['require',
col = {};
return this.tagCollection.constructor.getTableCols({
tag: {
typeName: {
label: "Classification",
cell: "html",
editable: false,
......
......@@ -113,7 +113,7 @@ define(['require',
/** BaseCollection's Static Attributes */
{
// Static functions
getTableCols: function(cols, collection) {
getTableCols: function(cols, collection, defaultSortDirection) {
var retCols = _.map(cols, function(v, k, l) {
var defaults = collection.constructor.tableCols[k];
if (!defaults) {
......@@ -121,7 +121,8 @@ define(['require',
defaults = {};
}
return _.extend({
'name': k
'name': k,
direction: defaultSortDirection ? defaultSortDirection : null,
}, defaults, v);
});
return retCols;
......
......@@ -55,7 +55,10 @@ define(['require', 'utils/Utils', 'marionette', 'backgrid', 'asBreadcrumbs', 'jq
return this.charAt(0).toUpperCase() + this.slice(1);
}
/*
* Overriding default sortType
*/
Backgrid.Column.prototype.defaults.sortType = "toggle";
/*
* Overriding Cell for adding custom className to Cell i.e <td>
......
......@@ -149,6 +149,20 @@ define(['require',
includeAtlasTableSorting: false,
showDefaultTableSorted: false,
/**
* [updateFullCollectionManually If collection was updated using silent true
* then need to update FullCollection Manually for correct sorting experience]
* @type {Boolean}
*/
updateFullCollectionManually: false,
sortOpts: {
sortColumn: "name",
sortDirection: "ascending"
},
/** ui events hash */
events: function() {
......@@ -183,26 +197,29 @@ define(['require',
initialize: function(options) {
this.limit = 25;
this.offset = 0;
_.extend(this, _.omit(options, 'gridOpts', 'atlasPaginationOpts'));
_.extend(this, _.omit(options, 'gridOpts', 'sortOpts', 'atlasPaginationOpts'));
_.extend(this, options.atlasPaginationOpts);
_.extend(this.gridOpts, options.gridOpts, { collection: this.collection, columns: this.columns });
_.extend(this.sortOpts, options.sortOpts);
if (this.includeAtlasTableSorting) {
var oldSortingRef = this.collection.setSorting;
this.collection.setSorting = function() {
this.state.pageSize = this.length
var val = oldSortingRef.apply(this, arguments);
val.fullCollection.models.sort();
val.fullCollection.sort();
this.comparator = function(next, previous, data) {
var getValue = function(options) {
var next = options.next,
previous = options.previous,
order = options.order;
if (order === -1) {
return next < previous ? -1 : 1;
if (next === previous) {
return null;
} else {
return next < previous ? 1 : -1;
if (order === -1) {
return next < previous ? -1 : 1;
} else {
return next < previous ? 1 : -1;
}
}
}
if (val.state && (!_.isNull(val.state.sortKey))) {
......@@ -263,11 +280,14 @@ define(['require',
removeCellDirection function - removes "ascending" and "descending"
which in turn removes chevrons from every 'sortable' header-cells*/
this.listenTo(this.collection, "backgrid:sorted", function(column, direction, collection) {
// backgrid:sorted fullCollection trigger required for icon chage
this.collection.fullCollection.trigger("backgrid:sorted", column, direction, collection)
if (this.includeAtlasTableSorting && this.updateFullCollectionManually) {
this.collection.fullCollection.reset(collection.toJSON(), { silent: true });
}
}, this);
this.listenTo(this, "grid:refresh", function() {
if (this.grid) {
this.grid.collection.fullCollection.reset(this.collection.entities, { silent: true });
this.grid.trigger("backgrid:refresh");
}
});
......@@ -337,8 +357,13 @@ define(['require',
this.grid = new Backgrid.Grid(this.gridOpts).on('backgrid:rendered', function() {
that.trigger('backgrid:manual:rendered', this)
});
this.rTableList.show(this.grid);
if (this.showDefaultTableSorted) {
this.grid.render();
this.grid.sort(this.sortOpts.sortColumn, this.sortOpts.sortDirection);
this.rTableList.show(this.grid);
} else {
this.rTableList.show(this.grid);
}
},
onShow: function() {
if (this.includeSizeAbleColumns) {
......
......@@ -264,6 +264,8 @@ define(['require',
includeSizeAbleColumns: false,
includeTableLoader: false,
includeAtlasTableSorting: true,
showDefaultTableSorted: true,
updateFullCollectionManually: true,
columnOpts: {
opts: {
initialColumnsVisible: null,
......@@ -445,9 +447,8 @@ define(['require',
attributeObject: dataOrCollection.entities,
referredEntities: dataOrCollection.referredEntities
});
that.searchCollection.referredEntities = dataOrCollection.referredEntities;
that.searchCollection.entities = dataOrCollection.entities;
that.searchCollection.reset(dataOrCollection.entities, { silent: true });
that.searchCollection.fullCollection.reset(dataOrCollection.entities, { silent: true });
}
......
......@@ -116,7 +116,7 @@ define(['require',
col = {};
return this.tagCollection.constructor.getTableCols({
tag: {
typeName: {
label: "Classification",
cell: "html",
editable: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment