diff options
Diffstat (limited to 'slick.grid.js')
-rwxr-xr-x | slick.grid.js | 101 |
1 files changed, 57 insertions, 44 deletions
diff --git a/slick.grid.js b/slick.grid.js index 85fc6e7..114440f 100755 --- a/slick.grid.js +++ b/slick.grid.js @@ -5,7 +5,7 @@ * Distributed under MIT license. * All rights reserved. * - * SlickGrid v1.4 + * SlickGrid v1.4.2 * * TODO: * - frozen columns @@ -40,6 +40,7 @@ * Must implement getFormatter(column). * editorFactory - (default null) A factory object responsible to creating an editor for a given cell. * Must implement getEditor(column). + * multiSelect - (default true) Enable multiple row selection. * * COLUMN DEFINITION (columns) OPTIONS: * id - Column ID. @@ -92,7 +93,7 @@ * and do proper cleanup. * * - * @param {jQuery} $container Container object to create the grid in. + * @param {NOde} container Container node to create the grid in. * @param {Array} or {Object} data An array of objects for databinding. * @param {Array} columns An array of column definitions. * @param {Object} options Grid options. @@ -207,7 +208,7 @@ if (!jQuery.fn.drag) { // SlickGrid class implementation (available as Slick.Grid) /** @constructor */ - function SlickGrid($container,data,columns,options) { + function SlickGrid(container,data,columns,options) { /// <summary> /// Create and manage virtual grid in the specified $container, /// connecting it to the specified data source. Data is presented @@ -241,7 +242,8 @@ if (!jQuery.fn.drag) { formatterFactory: null, editorFactory: null, cellHighlightCssClass: "highlighted", - cellFlashingCssClass: "flashing" + cellFlashingCssClass: "flashing", + multiSelect: true }, gridData, gridDataGetLength, gridDataGetItem; @@ -265,6 +267,7 @@ if (!jQuery.fn.drag) { var scrollDir = 1; // private + var $container; var uid = "slickgrid_" + Math.round(1000000 * Math.random()); var self = this; var $headerScroller; @@ -324,6 +327,8 @@ if (!jQuery.fn.drag) { /// This function is called by the constructor. /// </summary> + $container = $(container); + gridData = data; gridDataGetLength = gridData.getLength || defaultGetLength; gridDataGetItem = gridData.getItem || defaultGetItem; @@ -353,15 +358,9 @@ if (!jQuery.fn.drag) { .addClass(uid) .addClass("ui-widget"); - switch ($container.css("position")) { - case "absolute": // if the container is already positioning origin, keep it as it is - case "relative": - case "fixed": - break; - default: // container is not a positioning origin, convert it to one - $container.css("position","relative"); - break; - } + // set up a positioning container if needed + if (!/relative|absolute|fixed/.test($container.css("position"))) + $container.css("position","relative"); $headerScroller = $("<div class='slick-header ui-state-default' style='overflow:hidden;position:relative;' />").appendTo($container); $headers = $("<div class='slick-header-columns' style='width:100000px; left:-10000px' />").appendTo($headerScroller); @@ -401,15 +400,15 @@ if (!jQuery.fn.drag) { resizeAndRender(); bindAncestorScrollEvents(); - $viewport.bind("scroll", handleScroll); - $container.bind("resize", resizeAndRender); - $canvas.bind("keydown", handleKeyDown); - $canvas.bind("click", handleClick); - $canvas.bind("dblclick", handleDblClick); - $canvas.bind("contextmenu", handleContextMenu); - $canvas.bind("mouseover", handleHover); - $headerScroller.bind("contextmenu", handleHeaderContextMenu); - $headerScroller.bind("click", handleHeaderClick); + $viewport.bind("scroll.slickgrid", handleScroll); + $container.bind("resize.slickgrid", resizeAndRender); + $canvas.bind("keydown.slickgrid", handleKeyDown); + $canvas.bind("click.slickgrid", handleClick); + $canvas.bind("dblclick.slickgrid", handleDblClick); + $canvas.bind("contextmenu.slickgrid", handleContextMenu); + $canvas.bind("mouseover.slickgrid", handleHover); + $headerScroller.bind("contextmenu.slickgrid", handleHeaderContextMenu); + $headerScroller.bind("click.slickgrid", handleHeaderClick); } function measureScrollbar() { @@ -826,7 +825,7 @@ if (!jQuery.fn.drag) { }) .bind("drag", function(e,dd) { if (dd.mode == MOVE_ROWS) { - var top = e.clientY - $(this).offset().top; + var top = e.pageY - $(this).offset().top; dd.selectionProxy.css("top",top-5); var insertBefore = Math.max(0,Math.min(Math.round(top/options.rowHeight),gridDataGetLength())); @@ -900,7 +899,7 @@ if (!jQuery.fn.drag) { var rules = [ "." + uid + " .slick-header-column { left: 10000px; }", "." + uid + " .slick-header-columns-secondary { height:" + options.secondaryHeaderRowHeight + "px; }", - "." + uid + " .slick-cell { height:" + rowHeight + "px; line-height:" + rowHeight + "px; }" + "." + uid + " .slick-cell { height:" + rowHeight + "px; }" ]; for (var i=0; i<columns.length; i++) { @@ -951,7 +950,7 @@ if (!jQuery.fn.drag) { if (self.onBeforeDestroy) { self.onBeforeDestroy(); } if ($headers.sortable) { $headers.sortable("destroy"); } unbindAncestorScrollEvents(); - $container.unbind("resize", resizeCanvas); + $container.unbind(".slickgrid"); removeCssRules(); $canvas.unbind("draginit dragstart dragend drag"); @@ -1353,6 +1352,7 @@ if (!jQuery.fn.drag) { function updateRowCount() { var newRowCount = gridDataGetLength() + (options.enableAddRow?1:0) + (options.leaveSpaceForNewRows?numVisibleRows-1:0); var oldH = h; + // remove the rows that are now outside of the data range // this helps avoid redundant calls to .removeRow() when the size of the data decreased by thousands of rows var l = options.enableAddRow ? gridDataGetLength() : gridDataGetLength() - 1; @@ -1705,28 +1705,29 @@ if (!jQuery.fn.drag) { var selection = getSelectedRows(); var idx = $.inArray(row, selection); - if (!e.ctrlKey && !e.shiftKey) { + if (!e.ctrlKey && !e.shiftKey && !e.metaKey) { selection = [row]; } - else if (idx === -1 && e.ctrlKey) { - selection.push(row); - } - else if (idx !== -1 && e.ctrlKey) { - selection = $.grep(selection, function(o, i) { return (o !== row); }); - } - else if (selection.length && e.shiftKey) { - var last = selection.pop(); - var from = Math.min(row, last); - var to = Math.max(row, last); - selection = []; - for (var i = from; i <= to; i++) { - if (i !== last) { - selection.push(i); + else if (options.multiSelect) { + if (idx === -1 && (e.ctrlKey || e.metaKey)) { + selection.push(row); + } + else if (idx !== -1 && (e.ctrlKey || e.metaKey)) { + selection = $.grep(selection, function(o, i) { return (o !== row); }); + } + else if (selection.length && e.shiftKey) { + var last = selection.pop(); + var from = Math.min(row, last); + var to = Math.max(row, last); + selection = []; + for (var i = from; i <= to; i++) { + if (i !== last) { + selection.push(i); + } } + selection.push(last); } - selection.push(last); } - resetCurrentCell(); setSelectedRows(selection); if (self.onSelectedRowsChanged) { @@ -1829,7 +1830,6 @@ if (!jQuery.fn.drag) { } function handleHeaderClick(e) { - var $col = $(e.target).closest(".slick-header-column"); if ($col.length ==0) { return; } var column = columns[getSiblingIndex($col[0])]; @@ -1871,6 +1871,17 @@ if (!jQuery.fn.drag) { return {row:row,cell:cell-1}; } + function getCellFromEvent(e) { + var $cell = $(e.target).closest(".slick-cell", $canvas); + if (!$cell.length) + return null; + + return { + row: $cell.parent().attr("row") | 0, + cell: getSiblingIndex($cell[0]) + }; + } + function getCellNodeBox(row,cell) { if (!cellExists(row,cell)) return null; @@ -2402,7 +2413,7 @@ if (!jQuery.fn.drag) { // Public API $.extend(this, { - "slickGridVersion": "1.4", + "slickGridVersion": "1.4.2", // Events "onSort": null, @@ -2450,6 +2461,7 @@ if (!jQuery.fn.drag) { "resizeCanvas": resizeCanvas, "updateRowCount": updateRowCount, "getCellFromPoint": getCellFromPoint, + "getCellFromEvent": getCellFromEvent, "getCurrentCell": getCurrentCell, "getCurrentCellNode": getCurrentCellNode, "resetCurrentCell": resetCurrentCell, @@ -2471,6 +2483,7 @@ if (!jQuery.fn.drag) { "setSortColumn": setSortColumn, "getCurrentCellPosition" : getCurrentCellPosition, "getGridPosition": getGridPosition, + // IEditor implementation "getEditController": getEditController }); |