From 7460ac01be197815b4d789947fa2d40767c761d0 Mon Sep 17 00:00:00 2001 From: Euge Gimelberg Date: Mon, 18 Jul 2016 14:54:33 -0700 Subject: [PATCH] Fix bug where removing a model from the collection does not adjust the bulk selection of the model --- dist/backdraft.js | 2 +- spec/plugins/data_table/local.js | 13 +++++++++++++ src/plugins/data_table/data_table.js | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dist/backdraft.js b/dist/backdraft.js index 82514f32..489db5c2 100644 --- a/dist/backdraft.js +++ b/dist/backdraft.js @@ -1789,7 +1789,6 @@ _.extend(Plugin.factory, { event.stopImmediatePropagation(); } }); - // default sort handler for column with index self.dataTable.fnSortListener($('.DataTables_sort_wrapper', this), index); }); @@ -1903,6 +1902,7 @@ _.extend(Plugin.factory, { cache.unset(model); row.close(); }); + this.selectionManager.process(model, false); this._triggerChangeSelection(); }, diff --git a/spec/plugins/data_table/local.js b/spec/plugins/data_table/local.js index b0a21c56..f788262c 100644 --- a/spec/plugins/data_table/local.js +++ b/spec/plugins/data_table/local.js @@ -408,6 +408,19 @@ describe("DataTable Plugin", function() { table.filter("89"); }); + it("should adjust bulk selection after a model is removed from the collection", function() { + table = new app.Views.T({ collection : collection }); + table.render(); + var model = collection.find(function(m) { + return m.id === 89; + }); + table.filter("hi 88"); + table.selectAllVisible(true); + expect(table.selectedModels().length).toEqual(1); + collection.remove(model); + expect(table.selectedModels().length).toEqual(0); + }); + it("should uncheck the header bulk checkbox when a filter is applied and the result set is empty", function(done) { table = new app.Views.T({ collection : collection }); table.render(); diff --git a/src/plugins/data_table/data_table.js b/src/plugins/data_table/data_table.js index fd84750d..e3eee182 100644 --- a/src/plugins/data_table/data_table.js +++ b/src/plugins/data_table/data_table.js @@ -552,6 +552,7 @@ var LocalDataTable = (function() { cache.unset(model); row.close(); }); + this.selectionManager.process(model, false); this._triggerChangeSelection(); },