[minor] Fix getCell, reset sort action, set minWidth only once

This commit is contained in:
Faris Ansari 2017-10-01 12:41:41 +05:30
parent fa6a582a45
commit 0db68e46d5
3 changed files with 23 additions and 7 deletions

View File

@ -352,14 +352,17 @@ var ReGrid = function () {
margin: 0 margin: 0
}); });
this.minWidthMap = []; this.minWidthMap = (0, _utils.getDefault)(this.minWidthMap, []);
// set the width for each column // set the width for each column
this.header.find('.data-table-col').each(function () { this.header.find('.data-table-col').each(function () {
var col = (0, _jQuery2.default)(this); var col = (0, _jQuery2.default)(this);
var width = col.find('.content').width(); var width = col.find('.content').width();
var colIndex = col.attr('data-col-index'); var colIndex = col.attr('data-col-index');
self.minWidthMap[colIndex] = width; if (!self.minWidthMap[colIndex]) {
// only set this once
self.minWidthMap[colIndex] = width;
}
self.setColumnWidth(colIndex, width); self.setColumnWidth(colIndex, width);
}); });
@ -501,6 +504,10 @@ var ReGrid = function () {
var sortAction = (0, _utils.getDefault)($cell.attr('data-sort-action'), 'none'); var sortAction = (0, _utils.getDefault)($cell.attr('data-sort-action'), 'none');
var colIndex = $cell.attr('data-col-index'); var colIndex = $cell.attr('data-col-index');
// reset sort indicator
self.header.find('.sort-indicator').text('');
self.header.find('.data-table-col').attr('data-sort-action', 'none');
if (sortAction === 'none') { if (sortAction === 'none') {
$cell.attr('data-sort-action', 'asc'); $cell.attr('data-sort-action', 'asc');
$cell.find('.sort-indicator').text('▲'); $cell.find('.sort-indicator').text('▲');
@ -656,7 +663,9 @@ var ReGrid = function () {
value: function getCell(rowIndex, colIndex) { value: function getCell(rowIndex, colIndex) {
rowIndex = +rowIndex; rowIndex = +rowIndex;
colIndex = +colIndex; colIndex = +colIndex;
return this.data.rows[rowIndex][colIndex]; return this.data.rows.find(function (row) {
return row[0].rowIndex === rowIndex;
})[colIndex];
} }
}, { }, {
key: 'getColumnHeaderElement', key: 'getColumnHeaderElement',

File diff suppressed because one or more lines are too long

View File

@ -235,14 +235,17 @@ export default class ReGrid {
margin: 0 margin: 0
}); });
this.minWidthMap = []; this.minWidthMap = getDefault(this.minWidthMap, []);
// set the width for each column // set the width for each column
this.header.find('.data-table-col').each(function () { this.header.find('.data-table-col').each(function () {
const col = $(this); const col = $(this);
const width = col.find('.content').width(); const width = col.find('.content').width();
const colIndex = col.attr('data-col-index'); const colIndex = col.attr('data-col-index');
self.minWidthMap[colIndex] = width; if (!self.minWidthMap[colIndex]) {
// only set this once
self.minWidthMap[colIndex] = width;
}
self.setColumnWidth(colIndex, width); self.setColumnWidth(colIndex, width);
}); });
@ -375,6 +378,10 @@ export default class ReGrid {
const sortAction = getDefault($cell.attr('data-sort-action'), 'none'); const sortAction = getDefault($cell.attr('data-sort-action'), 'none');
const colIndex = $cell.attr('data-col-index'); const colIndex = $cell.attr('data-col-index');
// reset sort indicator
self.header.find('.sort-indicator').text('');
self.header.find('.data-table-col').attr('data-sort-action', 'none');
if (sortAction === 'none') { if (sortAction === 'none') {
$cell.attr('data-sort-action', 'asc'); $cell.attr('data-sort-action', 'asc');
$cell.find('.sort-indicator').text('▲'); $cell.find('.sort-indicator').text('▲');
@ -515,7 +522,7 @@ export default class ReGrid {
getCell(rowIndex, colIndex) { getCell(rowIndex, colIndex) {
rowIndex = +rowIndex; rowIndex = +rowIndex;
colIndex = +colIndex; colIndex = +colIndex;
return this.data.rows[rowIndex][colIndex]; return this.data.rows.find(row => row[0].rowIndex === rowIndex)[colIndex];
} }
getColumnHeaderElement(colIndex) { getColumnHeaderElement(colIndex) {