Skip to content

Commit 40d9762

Browse files
committed
Merged in Daptiv changes.
- ADDED: "toolTipMaxLength" option. - FIXED: not all rows getting removed by updateRowCount(). - ADDED: onHeaderContextMenu event now passes in a column definition as a second parameter. - ADDED: "getGridPosition" method.
1 parent 2703dd4 commit 40d9762

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

slick.grid.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ if (!jQuery.fn.drag) {
237237
secondaryHeaderRowHeight: 25,
238238
syncColumnCellResize: false,
239239
enableAutoTooltips: true,
240+
toolTipMaxLength: null,
240241
formatterFactory: null,
241242
editorFactory: null,
242243
cellHighlightCssClass: "highlighted",
@@ -245,6 +246,7 @@ if (!jQuery.fn.drag) {
245246
gridData, gridDataGetLength, gridDataGetItem;
246247

247248
var columnDefaults = {
249+
name: "",
248250
resizable: true,
249251
sortable: false,
250252
minWidth: 30
@@ -510,6 +512,7 @@ if (!jQuery.fn.drag) {
510512
.html("<span class='slick-column-name'>" + m.name + "</span>")
511513
.width(m.width - headerColumnWidthDiff)
512514
.attr("title", m.toolTip || m.name || "")
515+
.data("fieldId", m.id)
513516
.appendTo($headers);
514517

515518
if (options.enableColumnReorder || m.sortable) {
@@ -951,6 +954,7 @@ if (!jQuery.fn.drag) {
951954
$container.unbind("resize", resizeCanvas);
952955
removeCssRules();
953956

957+
$canvas.unbind("draginit dragstart dragend drag");
954958
$container.empty().removeClass(uid);
955959
}
956960

@@ -1086,6 +1090,7 @@ if (!jQuery.fn.drag) {
10861090
removeCssRules();
10871091
createCssRules();
10881092
resizeAndRender();
1093+
handleScroll();
10891094
}
10901095

10911096
function getOptions() {
@@ -1344,7 +1349,14 @@ if (!jQuery.fn.drag) {
13441349
function updateRowCount() {
13451350
var newRowCount = gridDataGetLength() + (options.enableAddRow?1:0) + (options.leaveSpaceForNewRows?numVisibleRows-1:0);
13461351
var oldH = h;
1347-
1352+
// remove the rows that are now outside of the data range
1353+
// this helps avoid redundant calls to .removeRow() when the size of the data decreased by thousands of rows
1354+
var l = options.enableAddRow ? gridDataGetLength() : gridDataGetLength() - 1;
1355+
for (var i in rowsCache) {
1356+
if (i >= l) {
1357+
removeRowFromCache(i);
1358+
}
1359+
}
13481360
th = Math.max(options.rowHeight * newRowCount, viewportH - scrollbarDimensions.height);
13491361
if (th < maxSupportedCssHeight) {
13501362
// just one page
@@ -1669,7 +1681,7 @@ if (!jQuery.fn.drag) {
16691681
}
16701682

16711683
function handleClick(e) {
1672-
var $cell = $(e.target).closest(".slick-cell");
1684+
var $cell = $(e.target).closest(".slick-cell", $canvas);
16731685
if ($cell.length === 0) { return; }
16741686

16751687
// are we editing this cell?
@@ -1749,7 +1761,7 @@ if (!jQuery.fn.drag) {
17491761
}
17501762

17511763
function handleContextMenu(e) {
1752-
var $cell = $(e.target).closest(".slick-cell");
1764+
var $cell = $(e.target).closest(".slick-cell", $canvas);
17531765
if ($cell.length === 0) { return; }
17541766

17551767
// are we editing this cell?
@@ -1775,7 +1787,7 @@ if (!jQuery.fn.drag) {
17751787
}
17761788

17771789
function handleDblClick(e) {
1778-
var $cell = $(e.target).closest(".slick-cell");
1790+
var $cell = $(e.target).closest(".slick-cell", $canvas);
17791791
if ($cell.length === 0) { return; }
17801792

17811793
// are we editing this cell?
@@ -1807,8 +1819,8 @@ if (!jQuery.fn.drag) {
18071819
function handleHeaderContextMenu(e) {
18081820
if (self.onHeaderContextMenu && options.editorLock.commitCurrentEdit()) {
18091821
e.preventDefault();
1810-
// TODO: figure out which column was acted on and pass it as a param to the handler
1811-
self.onHeaderContextMenu(e);
1822+
var selectedElement = $(e.target).closest(".slick-header-column", ".slick-header-columns");
1823+
self.onHeaderContextMenu(e, columns[self.getColumnIndex(selectedElement.data("fieldId"))]);
18121824
}
18131825
}
18141826

@@ -1827,9 +1839,10 @@ if (!jQuery.fn.drag) {
18271839
function handleHover(e) {
18281840
if (!options.enableAutoTooltips) return;
18291841
var $cell = $(e.target).closest(".slick-cell",$canvas);
1830-
if ($cell && $cell.length) {
1842+
if ($cell.length) {
18311843
if ($cell.innerWidth() < $cell[0].scrollWidth) {
1832-
$cell.attr("title", $.trim($cell.text()));
1844+
var text = $.trim($cell.text());
1845+
$cell.attr("title", (options.toolTipMaxLength && text.length > options.toolTipMaxLength) ? text.substr(0, options.toolTipMaxLength - 3) + "..." : text);
18331846
}
18341847
else {
18351848
$cell.attr("title","");
@@ -1915,7 +1928,7 @@ if (!jQuery.fn.drag) {
19151928

19161929
currentCellNode = newCell;
19171930

1918-
if (currentCellNode !== null) {
1931+
if (currentCellNode != null) {
19191932
currentRow = parseInt($(currentCellNode).parent().attr("row"), 10);
19201933
currentCell = getSiblingIndex(currentCellNode);
19211934

@@ -2113,6 +2126,9 @@ if (!jQuery.fn.drag) {
21132126
return absBox(currentCellNode);
21142127
}
21152128

2129+
function getGridPosition(){
2130+
return absBox($container[0])
2131+
}
21162132
function handleCurrentCellPositionChange() {
21172133
if (!currentCellNode) return;
21182134
var cellBox;
@@ -2449,7 +2465,7 @@ if (!jQuery.fn.drag) {
24492465
"hideSecondaryHeaderRow": hideSecondaryHeaderRow,
24502466
"setSortColumn": setSortColumn,
24512467
"getCurrentCellPosition" : getCurrentCellPosition,
2452-
2468+
"getGridPosition": getGridPosition,
24532469
// IEditor implementation
24542470
"getEditController": getEditController
24552471
});

0 commit comments

Comments
 (0)