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

Core: Updates header row on refresh #303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/jsgrid.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
pageClass: "jsgrid-pager-page",
currentPageClass: "jsgrid-pager-current-page",

refreshHeader: false,

customLoading: false,
pageLoading: false,

Expand Down Expand Up @@ -300,6 +302,7 @@
case "filtering":
case "inserting":
case "paging":
case "refreshHeader":
this.refresh();
break;
case "loadStrategy":
Expand Down Expand Up @@ -520,6 +523,7 @@
this._refreshContent();
this._refreshPager();
this._refreshSize();
this._refreshHeaderRow();

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

_refreshHeaderRow: function() {
if (this.refreshHeader) {
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
28 changes: 28 additions & 0 deletions tests/jsgrid.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,34 @@ $(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('option', 'refreshHeader', true);

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 direction class is kept');

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

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

module("inserting");

Expand Down