Skip to content

Commit

Permalink
Core: Updates header row on refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
kerro committed Jun 6, 2016
1 parent a327bc8 commit 7667d08
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/jsgrid.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@
this._refreshContent();
this._refreshPager();
this._refreshSize();
this._refreshHeaderRow();

this._callEventHandler(this.onRefreshed);
},
Expand Down Expand Up @@ -554,6 +555,31 @@
}
},

_refreshHeaderRow: function() {
var $headerRow = this._headerRow;
this._eachField(function(field, index) {
this._refreshHeaderCell($headerRow.children().eq(index), field, index);
});
},

_refreshHeaderCell: function($cell, field, index) {
var sortableDirClass = $cell.hasClass(this.sortAscClass) ? this.sortAscClass :
$cell.hasClass(this.sortDescClass) ? this.sortDescClass : '';

$cell.removeClass();

this._prepareCell($cell, field, "headercss");

$cell.off("click");
if(this.sorting && field.sorting) {
$cell.addClass(sortableDirClass)
.addClass(this.sortableClass)
.on("click", $.proxy(function() {
this.sort(index);
}, this));
}
},

_createNoDataRow: function() {
var noDataContent = getOrApply(this.noDataContent, this);

Expand Down
26 changes: 26 additions & 0 deletions tests/jsgrid.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,32 @@ $(function() {
equal($grid.find("." + grid.evenRowClass).eq(0).children().length, 1, "even data row single cell");
});

test("refresh updates header row", function() {
var $element = $("#jsGrid"),
gridOptions = {
fields: [
{ name: "field", align: "right", sorting: true},
],
sorting: true
};

var grid = new Grid($element, gridOptions);

var $th = grid._headerRow.find("th").eq(0);
$th.trigger("click");

$element.jsGrid('option', 'fields')[0].align = 'left';
$element.jsGrid('refresh');

ok(!$th.hasClass('jsgrid-align-right'), 'align right class is removed');
ok($th.hasClass('jsgrid-align-left'), 'align left class is attached');
ok($th.hasClass(grid.sortAscClass), 'sort class direction is kept');

$element.jsGrid('option', 'fields')[0].sorting = false;
$element.jsGrid('refresh');

ok(!$th.hasClass(grid.sortAscClass), 'sort class is removed');
});

module("inserting");

Expand Down

0 comments on commit 7667d08

Please sign in to comment.