primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,20 @@
Copyright (c) 2010 Michael Leibman, http://github.com/mleibman/slickgrid
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,25 @@
# Welcome to SlickGrid
Find documentation and examples in [the wiki](https://github.com/mleibman/SlickGrid/wiki).
**UPDATE: March 5th, 2014 - I have too many things going on in my life right now to really give SlickGrid support and development the time and attention it deserves. I am not stopping it, but I will most likely be unresponsive for some time. Sorry.**
## SlickGrid is an advanced JavaScript grid/spreadsheet component
Some highlights:
* Adaptive virtual scrolling (handle hundreds of thousands of rows with extreme responsiveness)
* Extremely fast rendering speed
* Supports jQuery UI Themes
* Background post-rendering for richer cells
* Configurable & customizable
* Full keyboard navigation
* Column resize/reorder/show/hide
* Column autosizing & force-fit
* Pluggable cell formatters & editors
* Support for editing and creating new rows.
* Grouping, filtering, custom aggregators, and more!
* Advanced detached & multi-field editors with undo/redo support.
* “GlobalEditorLock” to manage concurrent edits in cases where multiple Views on a page can edit the same data.
* Support for [millions of rows](http://stackoverflow.com/a/2569488/1269037)

View File

@ -0,0 +1,31 @@
.slick-columnpicker {
border: 1px solid #718BB7;
background: #f0f0f0;
padding: 6px;
-moz-box-shadow: 2px 2px 2px silver;
-webkit-box-shadow: 2px 2px 2px silver;
box-shadow: 2px 2px 2px silver;
min-width: 100px;
cursor: default;
}
.slick-columnpicker li {
list-style: none;
margin: 0;
padding: 0;
background: none;
}
.slick-columnpicker input {
margin: 4px;
}
.slick-columnpicker li a {
display: block;
padding: 4px;
font-weight: bold;
}
.slick-columnpicker li a:hover {
background: white;
}

View File

@ -0,0 +1,152 @@
(function ($) {
function SlickColumnPicker(columns, grid, options) {
var $menu;
var columnCheckboxes;
var defaults = {
fadeSpeed:250
};
function init() {
grid.onHeaderContextMenu.subscribe(handleHeaderContextMenu);
grid.onColumnsReordered.subscribe(updateColumnOrder);
options = $.extend({}, defaults, options);
$menu = $("<span class='slick-columnpicker' style='display:none;position:absolute;z-index:20;' />").appendTo(document.body);
$menu.bind("mouseleave", function (e) {
$(this).fadeOut(options.fadeSpeed)
});
$menu.bind("click", updateColumn);
}
function destroy() {
grid.onHeaderContextMenu.unsubscribe(handleHeaderContextMenu);
grid.onColumnsReordered.unsubscribe(updateColumnOrder);
$menu.remove();
}
function handleHeaderContextMenu(e, args) {
e.preventDefault();
$menu.empty();
updateColumnOrder();
columnCheckboxes = [];
var $li, $input;
for (var i = 0; i < columns.length; i++) {
$li = $("<li />").appendTo($menu);
$input = $("<input type='checkbox' />").data("column-id", columns[i].id);
columnCheckboxes.push($input);
if (grid.getColumnIndex(columns[i].id) != null) {
$input.attr("checked", "checked");
}
$("<label />")
.text(columns[i].name)
.prepend($input)
.appendTo($li);
}
$("<hr/>").appendTo($menu);
$li = $("<li />").appendTo($menu);
$input = $("<input type='checkbox' />").data("option", "autoresize");
$("<label />")
.text("Force fit columns")
.prepend($input)
.appendTo($li);
if (grid.getOptions().forceFitColumns) {
$input.attr("checked", "checked");
}
$li = $("<li />").appendTo($menu);
$input = $("<input type='checkbox' />").data("option", "syncresize");
$("<label />")
.text("Synchronous resize")
.prepend($input)
.appendTo($li);
if (grid.getOptions().syncColumnCellResize) {
$input.attr("checked", "checked");
}
$menu
.css("top", e.pageY - 10)
.css("left", e.pageX - 10)
.fadeIn(options.fadeSpeed);
}
function updateColumnOrder() {
// Because columns can be reordered, we have to update the `columns`
// to reflect the new order, however we can't just take `grid.getColumns()`,
// as it does not include columns currently hidden by the picker.
// We create a new `columns` structure by leaving currently-hidden
// columns in their original ordinal position and interleaving the results
// of the current column sort.
var current = grid.getColumns().slice(0);
var ordered = new Array(columns.length);
for (var i = 0; i < ordered.length; i++) {
if ( grid.getColumnIndex(columns[i].id) === undefined ) {
// If the column doesn't return a value from getColumnIndex,
// it is hidden. Leave it in this position.
ordered[i] = columns[i];
} else {
// Otherwise, grab the next visible column.
ordered[i] = current.shift();
}
}
columns = ordered;
}
function updateColumn(e) {
if ($(e.target).data("option") == "autoresize") {
if (e.target.checked) {
grid.setOptions({forceFitColumns:true});
grid.autosizeColumns();
} else {
grid.setOptions({forceFitColumns:false});
}
return;
}
if ($(e.target).data("option") == "syncresize") {
if (e.target.checked) {
grid.setOptions({syncColumnCellResize:true});
} else {
grid.setOptions({syncColumnCellResize:false});
}
return;
}
if ($(e.target).is(":checkbox")) {
var visibleColumns = [];
$.each(columnCheckboxes, function (i, e) {
if ($(this).is(":checked")) {
visibleColumns.push(columns[i]);
}
});
if (!visibleColumns.length) {
$(e.target).attr("checked", "checked");
return;
}
grid.setColumns(visibleColumns);
}
}
function getAllColumns() {
return columns;
}
init();
return {
"getAllColumns": getAllColumns,
"destroy": destroy
};
}
// Slick.Controls.ColumnPicker
$.extend(true, window, { Slick:{ Controls:{ ColumnPicker:SlickColumnPicker }}});
})(jQuery);

View File

@ -0,0 +1,41 @@
.slick-pager {
width: 100%;
height: 26px;
border: 1px solid gray;
border-top: 0;
background: url('../images/header-columns-bg.gif') repeat-x center bottom;
vertical-align: middle;
}
.slick-pager .slick-pager-status {
display: inline-block;
padding: 6px;
}
.slick-pager .ui-icon-container {
display: inline-block;
margin: 2px;
border-color: gray;
}
.slick-pager .slick-pager-nav {
display: inline-block;
float: left;
padding: 2px;
}
.slick-pager .slick-pager-settings {
display: block;
float: right;
padding: 2px;
}
.slick-pager .slick-pager-settings * {
vertical-align: middle;
}
.slick-pager .slick-pager-settings a {
padding: 2px;
text-decoration: underline;
cursor: pointer;
}

View File

@ -0,0 +1,154 @@
(function ($) {
function SlickGridPager(dataView, grid, $container) {
var $status;
function init() {
dataView.onPagingInfoChanged.subscribe(function (e, pagingInfo) {
updatePager(pagingInfo);
});
constructPagerUI();
updatePager(dataView.getPagingInfo());
}
function getNavState() {
var cannotLeaveEditMode = !Slick.GlobalEditorLock.commitCurrentEdit();
var pagingInfo = dataView.getPagingInfo();
var lastPage = pagingInfo.totalPages - 1;
return {
canGotoFirst: !cannotLeaveEditMode && pagingInfo.pageSize != 0 && pagingInfo.pageNum > 0,
canGotoLast: !cannotLeaveEditMode && pagingInfo.pageSize != 0 && pagingInfo.pageNum != lastPage,
canGotoPrev: !cannotLeaveEditMode && pagingInfo.pageSize != 0 && pagingInfo.pageNum > 0,
canGotoNext: !cannotLeaveEditMode && pagingInfo.pageSize != 0 && pagingInfo.pageNum < lastPage,
pagingInfo: pagingInfo
}
}
function setPageSize(n) {
dataView.setRefreshHints({
isFilterUnchanged: true
});
dataView.setPagingOptions({pageSize: n});
}
function gotoFirst() {
if (getNavState().canGotoFirst) {
dataView.setPagingOptions({pageNum: 0});
}
}
function gotoLast() {
var state = getNavState();
if (state.canGotoLast) {
dataView.setPagingOptions({pageNum: state.pagingInfo.totalPages - 1});
}
}
function gotoPrev() {
var state = getNavState();
if (state.canGotoPrev) {
dataView.setPagingOptions({pageNum: state.pagingInfo.pageNum - 1});
}
}
function gotoNext() {
var state = getNavState();
if (state.canGotoNext) {
dataView.setPagingOptions({pageNum: state.pagingInfo.pageNum + 1});
}
}
function constructPagerUI() {
$container.empty();
var $nav = $("<span class='slick-pager-nav' />").appendTo($container);
var $settings = $("<span class='slick-pager-settings' />").appendTo($container);
$status = $("<span class='slick-pager-status' />").appendTo($container);
$settings
.append("<span class='slick-pager-settings-expanded' style='display:none'>Show: <a data=0>All</a><a data='-1'>Auto</a><a data=25>25</a><a data=50>50</a><a data=100>100</a></span>");
$settings.find("a[data]").click(function (e) {
var pagesize = $(e.target).attr("data");
if (pagesize != undefined) {
if (pagesize == -1) {
var vp = grid.getViewport();
setPageSize(vp.bottom - vp.top);
} else {
setPageSize(parseInt(pagesize));
}
}
});
var icon_prefix = "<span class='ui-state-default ui-corner-all ui-icon-container'><span class='ui-icon ";
var icon_suffix = "' /></span>";
$(icon_prefix + "ui-icon-lightbulb" + icon_suffix)
.click(function () {
$(".slick-pager-settings-expanded").toggle()
})
.appendTo($settings);
$(icon_prefix + "ui-icon-seek-first" + icon_suffix)
.click(gotoFirst)
.appendTo($nav);
$(icon_prefix + "ui-icon-seek-prev" + icon_suffix)
.click(gotoPrev)
.appendTo($nav);
$(icon_prefix + "ui-icon-seek-next" + icon_suffix)
.click(gotoNext)
.appendTo($nav);
$(icon_prefix + "ui-icon-seek-end" + icon_suffix)
.click(gotoLast)
.appendTo($nav);
$container.find(".ui-icon-container")
.hover(function () {
$(this).toggleClass("ui-state-hover");
});
$container.children().wrapAll("<div class='slick-pager' />");
}
function updatePager(pagingInfo) {
var state = getNavState();
$container.find(".slick-pager-nav span").removeClass("ui-state-disabled");
if (!state.canGotoFirst) {
$container.find(".ui-icon-seek-first").addClass("ui-state-disabled");
}
if (!state.canGotoLast) {
$container.find(".ui-icon-seek-end").addClass("ui-state-disabled");
}
if (!state.canGotoNext) {
$container.find(".ui-icon-seek-next").addClass("ui-state-disabled");
}
if (!state.canGotoPrev) {
$container.find(".ui-icon-seek-prev").addClass("ui-state-disabled");
}
if (pagingInfo.pageSize == 0) {
var totalRowsCount = dataView.getItems().length;
var visibleRowsCount = pagingInfo.totalRows;
if (visibleRowsCount < totalRowsCount) {
$status.text("Showing " + visibleRowsCount + " of " + totalRowsCount + " rows");
} else {
$status.text("Showing all " + totalRowsCount + " rows");
}
$status.text("Showing all " + pagingInfo.totalRows + " rows");
} else {
$status.text("Showing page " + (pagingInfo.pageNum + 1) + " of " + pagingInfo.totalPages);
}
}
init();
}
// Slick.Controls.Pager
$.extend(true, window, { Slick:{ Controls:{ Pager:SlickGridPager }}});
})(jQuery);

View File

@ -0,0 +1,83 @@
(function ($) {
// Register namespace
$.extend(true, window, {
"Slick": {
"AutoTooltips": AutoTooltips
}
});
/**
* AutoTooltips plugin to show/hide tooltips when columns are too narrow to fit content.
* @constructor
* @param {boolean} [options.enableForCells=true] - Enable tooltip for grid cells
* @param {boolean} [options.enableForHeaderCells=false] - Enable tooltip for header cells
* @param {number} [options.maxToolTipLength=null] - The maximum length for a tooltip
*/
function AutoTooltips(options) {
var _grid;
var _self = this;
var _defaults = {
enableForCells: true,
enableForHeaderCells: false,
maxToolTipLength: null
};
/**
* Initialize plugin.
*/
function init(grid) {
options = $.extend(true, {}, _defaults, options);
_grid = grid;
if (options.enableForCells) _grid.onMouseEnter.subscribe(handleMouseEnter);
if (options.enableForHeaderCells) _grid.onHeaderMouseEnter.subscribe(handleHeaderMouseEnter);
}
/**
* Destroy plugin.
*/
function destroy() {
if (options.enableForCells) _grid.onMouseEnter.unsubscribe(handleMouseEnter);
if (options.enableForHeaderCells) _grid.onHeaderMouseEnter.unsubscribe(handleHeaderMouseEnter);
}
/**
* Handle mouse entering grid cell to add/remove tooltip.
* @param {jQuery.Event} e - The event
*/
function handleMouseEnter(e) {
var cell = _grid.getCellFromEvent(e);
if (cell) {
var $node = $(_grid.getCellNode(cell.row, cell.cell));
var text;
if ($node.innerWidth() < $node[0].scrollWidth) {
text = $.trim($node.text());
if (options.maxToolTipLength && text.length > options.maxToolTipLength) {
text = text.substr(0, options.maxToolTipLength - 3) + "...";
}
} else {
text = "";
}
$node.attr("title", text);
}
}
/**
* Handle mouse entering header cell to add/remove tooltip.
* @param {jQuery.Event} e - The event
* @param {object} args.column - The column definition
*/
function handleHeaderMouseEnter(e, args) {
var column = args.column,
$node = $(e.target).closest(".slick-header-column");
if (!column.toolTip) {
$node.attr("title", ($node.innerWidth() < $node[0].scrollWidth) ? column.name : "");
}
}
// Public API
$.extend(this, {
"init": init,
"destroy": destroy
});
}
})(jQuery);

View File

@ -0,0 +1,86 @@
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"CellCopyManager": CellCopyManager
}
});
function CellCopyManager() {
var _grid;
var _self = this;
var _copiedRanges;
function init(grid) {
_grid = grid;
_grid.onKeyDown.subscribe(handleKeyDown);
}
function destroy() {
_grid.onKeyDown.unsubscribe(handleKeyDown);
}
function handleKeyDown(e, args) {
var ranges;
if (!_grid.getEditorLock().isActive()) {
if (e.which == $.ui.keyCode.ESCAPE) {
if (_copiedRanges) {
e.preventDefault();
clearCopySelection();
_self.onCopyCancelled.notify({ranges: _copiedRanges});
_copiedRanges = null;
}
}
if (e.which == 67 && (e.ctrlKey || e.metaKey)) {
ranges = _grid.getSelectionModel().getSelectedRanges();
if (ranges.length != 0) {
e.preventDefault();
_copiedRanges = ranges;
markCopySelection(ranges);
_self.onCopyCells.notify({ranges: ranges});
}
}
if (e.which == 86 && (e.ctrlKey || e.metaKey)) {
if (_copiedRanges) {
e.preventDefault();
clearCopySelection();
ranges = _grid.getSelectionModel().getSelectedRanges();
_self.onPasteCells.notify({from: _copiedRanges, to: ranges});
_copiedRanges = null;
}
}
}
}
function markCopySelection(ranges) {
var columns = _grid.getColumns();
var hash = {};
for (var i = 0; i < ranges.length; i++) {
for (var j = ranges[i].fromRow; j <= ranges[i].toRow; j++) {
hash[j] = {};
for (var k = ranges[i].fromCell; k <= ranges[i].toCell; k++) {
hash[j][columns[k].id] = "copied";
}
}
}
_grid.setCellCssStyles("copy-manager", hash);
}
function clearCopySelection() {
_grid.removeCellCssStyles("copy-manager");
}
$.extend(this, {
"init": init,
"destroy": destroy,
"clearCopySelection": clearCopySelection,
"onCopyCells": new Slick.Event(),
"onCopyCancelled": new Slick.Event(),
"onPasteCells": new Slick.Event()
});
}
})(jQuery);

View File

@ -0,0 +1,66 @@
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"CellRangeDecorator": CellRangeDecorator
}
});
/***
* Displays an overlay on top of a given cell range.
*
* TODO:
* Currently, it blocks mouse events to DOM nodes behind it.
* Use FF and WebKit-specific "pointer-events" CSS style, or some kind of event forwarding.
* Could also construct the borders separately using 4 individual DIVs.
*
* @param {Grid} grid
* @param {Object} options
*/
function CellRangeDecorator(grid, options) {
var _elem;
var _defaults = {
selectionCssClass: 'slick-range-decorator',
selectionCss: {
"zIndex": "9999",
"border": "2px dashed red"
}
};
options = $.extend(true, {}, _defaults, options);
function show(range) {
if (!_elem) {
_elem = $("<div></div>", {css: options.selectionCss})
.addClass(options.selectionCssClass)
.css("position", "absolute")
.appendTo(grid.getCanvasNode());
}
var from = grid.getCellNodeBox(range.fromRow, range.fromCell);
var to = grid.getCellNodeBox(range.toRow, range.toCell);
_elem.css({
top: from.top - 1,
left: from.left - 1,
height: to.bottom - from.top - 2,
width: to.right - from.left - 2
});
return _elem;
}
function hide() {
if (_elem) {
_elem.remove();
_elem = null;
}
}
$.extend(this, {
"show": show,
"hide": hide
});
}
})(jQuery);

View File

@ -0,0 +1,113 @@
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"CellRangeSelector": CellRangeSelector
}
});
function CellRangeSelector(options) {
var _grid;
var _canvas;
var _dragging;
var _decorator;
var _self = this;
var _handler = new Slick.EventHandler();
var _defaults = {
selectionCss: {
"border": "2px dashed blue"
}
};
function init(grid) {
options = $.extend(true, {}, _defaults, options);
_decorator = new Slick.CellRangeDecorator(grid, options);
_grid = grid;
_canvas = _grid.getCanvasNode();
_handler
.subscribe(_grid.onDragInit, handleDragInit)
.subscribe(_grid.onDragStart, handleDragStart)
.subscribe(_grid.onDrag, handleDrag)
.subscribe(_grid.onDragEnd, handleDragEnd);
}
function destroy() {
_handler.unsubscribeAll();
}
function handleDragInit(e, dd) {
// prevent the grid from cancelling drag'n'drop by default
e.stopImmediatePropagation();
}
function handleDragStart(e, dd) {
var cell = _grid.getCellFromEvent(e);
if (_self.onBeforeCellRangeSelected.notify(cell) !== false) {
if (_grid.canCellBeSelected(cell.row, cell.cell)) {
_dragging = true;
e.stopImmediatePropagation();
}
}
if (!_dragging) {
return;
}
_grid.focus();
var start = _grid.getCellFromPoint(
dd.startX - $(_canvas).offset().left,
dd.startY - $(_canvas).offset().top);
dd.range = {start: start, end: {}};
return _decorator.show(new Slick.Range(start.row, start.cell));
}
function handleDrag(e, dd) {
if (!_dragging) {
return;
}
e.stopImmediatePropagation();
var end = _grid.getCellFromPoint(
e.pageX - $(_canvas).offset().left,
e.pageY - $(_canvas).offset().top);
if (!_grid.canCellBeSelected(end.row, end.cell)) {
return;
}
dd.range.end = end;
_decorator.show(new Slick.Range(dd.range.start.row, dd.range.start.cell, end.row, end.cell));
}
function handleDragEnd(e, dd) {
if (!_dragging) {
return;
}
_dragging = false;
e.stopImmediatePropagation();
_decorator.hide();
_self.onCellRangeSelected.notify({
range: new Slick.Range(
dd.range.start.row,
dd.range.start.cell,
dd.range.end.row,
dd.range.end.cell
)
});
}
$.extend(this, {
"init": init,
"destroy": destroy,
"onBeforeCellRangeSelected": new Slick.Event(),
"onCellRangeSelected": new Slick.Event()
});
}
})(jQuery);

View File

@ -0,0 +1,154 @@
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"CellSelectionModel": CellSelectionModel
}
});
function CellSelectionModel(options) {
var _grid;
var _canvas;
var _ranges = [];
var _self = this;
var _selector = new Slick.CellRangeSelector({
"selectionCss": {
"border": "2px solid black"
}
});
var _options;
var _defaults = {
selectActiveCell: true
};
function init(grid) {
_options = $.extend(true, {}, _defaults, options);
_grid = grid;
_canvas = _grid.getCanvasNode();
_grid.onActiveCellChanged.subscribe(handleActiveCellChange);
_grid.onKeyDown.subscribe(handleKeyDown);
grid.registerPlugin(_selector);
_selector.onCellRangeSelected.subscribe(handleCellRangeSelected);
_selector.onBeforeCellRangeSelected.subscribe(handleBeforeCellRangeSelected);
}
function destroy() {
_grid.onActiveCellChanged.unsubscribe(handleActiveCellChange);
_grid.onKeyDown.unsubscribe(handleKeyDown);
_selector.onCellRangeSelected.unsubscribe(handleCellRangeSelected);
_selector.onBeforeCellRangeSelected.unsubscribe(handleBeforeCellRangeSelected);
_grid.unregisterPlugin(_selector);
}
function removeInvalidRanges(ranges) {
var result = [];
for (var i = 0; i < ranges.length; i++) {
var r = ranges[i];
if (_grid.canCellBeSelected(r.fromRow, r.fromCell) && _grid.canCellBeSelected(r.toRow, r.toCell)) {
result.push(r);
}
}
return result;
}
function setSelectedRanges(ranges) {
_ranges = removeInvalidRanges(ranges);
_self.onSelectedRangesChanged.notify(_ranges);
}
function getSelectedRanges() {
return _ranges;
}
function handleBeforeCellRangeSelected(e, args) {
if (_grid.getEditorLock().isActive()) {
e.stopPropagation();
return false;
}
}
function handleCellRangeSelected(e, args) {
setSelectedRanges([args.range]);
}
function handleActiveCellChange(e, args) {
if (_options.selectActiveCell && args.row != null && args.cell != null) {
setSelectedRanges([new Slick.Range(args.row, args.cell)]);
}
}
function handleKeyDown(e) {
/***
* Кey codes
* 37 left
* 38 up
* 39 right
* 40 down
*/
var ranges, last;
var active = _grid.getActiveCell();
if ( active && e.shiftKey && !e.ctrlKey && !e.altKey &&
(e.which == 37 || e.which == 39 || e.which == 38 || e.which == 40) ) {
ranges = getSelectedRanges();
if (!ranges.length)
ranges.push(new Slick.Range(active.row, active.cell));
// keyboard can work with last range only
last = ranges.pop();
// can't handle selection out of active cell
if (!last.contains(active.row, active.cell))
last = new Slick.Range(active.row, active.cell);
var dRow = last.toRow - last.fromRow,
dCell = last.toCell - last.fromCell,
// walking direction
dirRow = active.row == last.fromRow ? 1 : -1,
dirCell = active.cell == last.fromCell ? 1 : -1;
if (e.which == 37) {
dCell -= dirCell;
} else if (e.which == 39) {
dCell += dirCell ;
} else if (e.which == 38) {
dRow -= dirRow;
} else if (e.which == 40) {
dRow += dirRow;
}
// define new selection range
var new_last = new Slick.Range(active.row, active.cell, active.row + dirRow*dRow, active.cell + dirCell*dCell);
if (removeInvalidRanges([new_last]).length) {
ranges.push(new_last);
var viewRow = dirRow > 0 ? new_last.toRow : new_last.fromRow;
var viewCell = dirCell > 0 ? new_last.toCell : new_last.fromCell;
_grid.scrollRowIntoView(viewRow);
_grid.scrollCellIntoView(viewRow, viewCell);
}
else
ranges.push(last);
setSelectedRanges(ranges);
e.preventDefault();
e.stopPropagation();
}
}
$.extend(this, {
"getSelectedRanges": getSelectedRanges,
"setSelectedRanges": setSelectedRanges,
"init": init,
"destroy": destroy,
"onSelectedRangesChanged": new Slick.Event()
});
}
})(jQuery);

View File

@ -0,0 +1,153 @@
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"CheckboxSelectColumn": CheckboxSelectColumn
}
});
function CheckboxSelectColumn(options) {
var _grid;
var _self = this;
var _handler = new Slick.EventHandler();
var _selectedRowsLookup = {};
var _defaults = {
columnId: "_checkbox_selector",
cssClass: null,
toolTip: "Select/Deselect All",
width: 30
};
var _options = $.extend(true, {}, _defaults, options);
function init(grid) {
_grid = grid;
_handler
.subscribe(_grid.onSelectedRowsChanged, handleSelectedRowsChanged)
.subscribe(_grid.onClick, handleClick)
.subscribe(_grid.onHeaderClick, handleHeaderClick)
.subscribe(_grid.onKeyDown, handleKeyDown);
}
function destroy() {
_handler.unsubscribeAll();
}
function handleSelectedRowsChanged(e, args) {
var selectedRows = _grid.getSelectedRows();
var lookup = {}, row, i;
for (i = 0; i < selectedRows.length; i++) {
row = selectedRows[i];
lookup[row] = true;
if (lookup[row] !== _selectedRowsLookup[row]) {
_grid.invalidateRow(row);
delete _selectedRowsLookup[row];
}
}
for (i in _selectedRowsLookup) {
_grid.invalidateRow(i);
}
_selectedRowsLookup = lookup;
_grid.render();
if (selectedRows.length && selectedRows.length == _grid.getDataLength()) {
_grid.updateColumnHeader(_options.columnId, "<input type='checkbox' checked='checked'>", _options.toolTip);
} else {
_grid.updateColumnHeader(_options.columnId, "<input type='checkbox'>", _options.toolTip);
}
}
function handleKeyDown(e, args) {
if (e.which == 32) {
if (_grid.getColumns()[args.cell].id === _options.columnId) {
// if editing, try to commit
if (!_grid.getEditorLock().isActive() || _grid.getEditorLock().commitCurrentEdit()) {
toggleRowSelection(args.row);
}
e.preventDefault();
e.stopImmediatePropagation();
}
}
}
function handleClick(e, args) {
// clicking on a row select checkbox
if (_grid.getColumns()[args.cell].id === _options.columnId && $(e.target).is(":checkbox")) {
// if editing, try to commit
if (_grid.getEditorLock().isActive() && !_grid.getEditorLock().commitCurrentEdit()) {
e.preventDefault();
e.stopImmediatePropagation();
return;
}
toggleRowSelection(args.row);
e.stopPropagation();
e.stopImmediatePropagation();
}
}
function toggleRowSelection(row) {
if (_selectedRowsLookup[row]) {
_grid.setSelectedRows($.grep(_grid.getSelectedRows(), function (n) {
return n != row
}));
} else {
_grid.setSelectedRows(_grid.getSelectedRows().concat(row));
}
}
function handleHeaderClick(e, args) {
if (args.column.id == _options.columnId && $(e.target).is(":checkbox")) {
// if editing, try to commit
if (_grid.getEditorLock().isActive() && !_grid.getEditorLock().commitCurrentEdit()) {
e.preventDefault();
e.stopImmediatePropagation();
return;
}
if ($(e.target).is(":checked")) {
var rows = [];
for (var i = 0; i < _grid.getDataLength(); i++) {
rows.push(i);
}
_grid.setSelectedRows(rows);
} else {
_grid.setSelectedRows([]);
}
e.stopPropagation();
e.stopImmediatePropagation();
}
}
function getColumnDefinition() {
return {
id: _options.columnId,
name: "<input type='checkbox'>",
toolTip: _options.toolTip,
field: "sel",
width: _options.width,
resizable: false,
sortable: false,
cssClass: _options.cssClass,
formatter: checkboxSelectionFormatter
};
}
function checkboxSelectionFormatter(row, cell, value, columnDef, dataContext) {
if (dataContext) {
return _selectedRowsLookup[row]
? "<input type='checkbox' checked='checked'>"
: "<input type='checkbox'>";
}
return null;
}
$.extend(this, {
"init": init,
"destroy": destroy,
"getColumnDefinition": getColumnDefinition
});
}
})(jQuery);

View File

@ -0,0 +1,39 @@
.slick-column-name,
.slick-sort-indicator {
/**
* This makes all "float:right" elements after it that spill over to the next line
* display way below the lower boundary of the column thus hiding them.
*/
display: inline-block;
float: left;
margin-bottom: 100px;
}
.slick-header-button {
display: inline-block;
float: right;
vertical-align: top;
margin: 1px;
/**
* This makes all "float:right" elements after it that spill over to the next line
* display way below the lower boundary of the column thus hiding them.
*/
margin-bottom: 100px;
height: 15px;
width: 15px;
background-repeat: no-repeat;
background-position: center center;
cursor: pointer;
}
.slick-header-button-hidden {
width: 0;
-webkit-transition: 0.2s width;
-ms-transition: 0.2s width;
transition: 0.2s width;
}
.slick-header-column:hover > .slick-header-button {
width: 15px;
}

View File

@ -0,0 +1,177 @@
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"Plugins": {
"HeaderButtons": HeaderButtons
}
}
});
/***
* A plugin to add custom buttons to column headers.
*
* USAGE:
*
* Add the plugin .js & .css files and register it with the grid.
*
* To specify a custom button in a column header, extend the column definition like so:
*
* var columns = [
* {
* id: 'myColumn',
* name: 'My column',
*
* // This is the relevant part
* header: {
* buttons: [
* {
* // button options
* },
* {
* // button options
* }
* ]
* }
* }
* ];
*
* Available button options:
* cssClass: CSS class to add to the button.
* image: Relative button image path.
* tooltip: Button tooltip.
* showOnHover: Only show the button on hover.
* handler: Button click handler.
* command: A command identifier to be passed to the onCommand event handlers.
*
* The plugin exposes the following events:
* onCommand: Fired on button click for buttons with 'command' specified.
* Event args:
* grid: Reference to the grid.
* column: Column definition.
* command: Button command identified.
* button: Button options. Note that you can change the button options in your
* event handler, and the column header will be automatically updated to
* reflect them. This is useful if you want to implement something like a
* toggle button.
*
*
* @param options {Object} Options:
* buttonCssClass: a CSS class to use for buttons (default 'slick-header-button')
* @class Slick.Plugins.HeaderButtons
* @constructor
*/
function HeaderButtons(options) {
var _grid;
var _self = this;
var _handler = new Slick.EventHandler();
var _defaults = {
buttonCssClass: "slick-header-button"
};
function init(grid) {
options = $.extend(true, {}, _defaults, options);
_grid = grid;
_handler
.subscribe(_grid.onHeaderCellRendered, handleHeaderCellRendered)
.subscribe(_grid.onBeforeHeaderCellDestroy, handleBeforeHeaderCellDestroy);
// Force the grid to re-render the header now that the events are hooked up.
_grid.setColumns(_grid.getColumns());
}
function destroy() {
_handler.unsubscribeAll();
}
function handleHeaderCellRendered(e, args) {
var column = args.column;
if (column.header && column.header.buttons) {
// Append buttons in reverse order since they are floated to the right.
var i = column.header.buttons.length;
while (i--) {
var button = column.header.buttons[i];
var btn = $("<div></div>")
.addClass(options.buttonCssClass)
.data("column", column)
.data("button", button);
if (button.showOnHover) {
btn.addClass("slick-header-button-hidden");
}
if (button.image) {
btn.css("backgroundImage", "url(" + button.image + ")");
}
if (button.cssClass) {
btn.addClass(button.cssClass);
}
if (button.tooltip) {
btn.attr("title", button.tooltip);
}
if (button.command) {
btn.data("command", button.command);
}
if (button.handler) {
btn.bind("click", button.handler);
}
btn
.bind("click", handleButtonClick)
.appendTo(args.node);
}
}
}
function handleBeforeHeaderCellDestroy(e, args) {
var column = args.column;
if (column.header && column.header.buttons) {
// Removing buttons via jQuery will also clean up any event handlers and data.
// NOTE: If you attach event handlers directly or using a different framework,
// you must also clean them up here to avoid memory leaks.
$(args.node).find("." + options.buttonCssClass).remove();
}
}
function handleButtonClick(e) {
var command = $(this).data("command");
var columnDef = $(this).data("column");
var button = $(this).data("button");
if (command != null) {
_self.onCommand.notify({
"grid": _grid,
"column": columnDef,
"command": command,
"button": button
}, e, _self);
// Update the header in case the user updated the button definition in the handler.
_grid.updateColumnHeader(columnDef.id);
}
// Stop propagation so that it doesn't register as a header click event.
e.preventDefault();
e.stopPropagation();
}
$.extend(this, {
"init": init,
"destroy": destroy,
"onCommand": new Slick.Event()
});
}
})(jQuery);

View File

@ -0,0 +1,59 @@
/* Menu button */
.slick-header-menubutton {
position: absolute;
right: 0;
top: 0;
bottom: 0;
width: 14px;
background-repeat: no-repeat;
background-position: left center;
background-image: url(../images/down.gif);
cursor: pointer;
display: none;
border-left: thin ridge silver;
}
.slick-header-column:hover > .slick-header-menubutton,
.slick-header-column-active .slick-header-menubutton {
display: inline-block;
}
/* Menu */
.slick-header-menu {
position: absolute;
display: inline-block;
margin: 0;
padding: 2px;
cursor: default;
}
/* Menu items */
.slick-header-menuitem {
list-style: none;
margin: 0;
padding: 0;
cursor: pointer;
}
.slick-header-menuicon {
display: inline-block;
width: 16px;
height: 16px;
vertical-align: middle;
margin-right: 4px;
background-repeat: no-repeat;
background-position: center center;
}
.slick-header-menucontent {
display: inline-block;
vertical-align: middle;
}
/* Disabled */
.slick-header-menuitem-disabled {
color: silver;
}

View File

@ -0,0 +1,275 @@
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"Plugins": {
"HeaderMenu": HeaderMenu
}
}
});
/***
* A plugin to add drop-down menus to column headers.
*
* USAGE:
*
* Add the plugin .js & .css files and register it with the grid.
*
* To specify a menu in a column header, extend the column definition like so:
*
* var columns = [
* {
* id: 'myColumn',
* name: 'My column',
*
* // This is the relevant part
* header: {
* menu: {
* items: [
* {
* // menu item options
* },
* {
* // menu item options
* }
* ]
* }
* }
* }
* ];
*
*
* Available menu options:
* tooltip: Menu button tooltip.
*
*
* Available menu item options:
* title: Menu item text.
* disabled: Whether the item is disabled.
* tooltip: Item tooltip.
* command: A command identifier to be passed to the onCommand event handlers.
* iconCssClass: A CSS class to be added to the menu item icon.
* iconImage: A url to the icon image.
*
*
* The plugin exposes the following events:
* onBeforeMenuShow: Fired before the menu is shown. You can customize the menu or dismiss it by returning false.
* Event args:
* grid: Reference to the grid.
* column: Column definition.
* menu: Menu options. Note that you can change the menu items here.
*
* onCommand: Fired on menu item click for buttons with 'command' specified.
* Event args:
* grid: Reference to the grid.
* column: Column definition.
* command: Button command identified.
* button: Button options. Note that you can change the button options in your
* event handler, and the column header will be automatically updated to
* reflect them. This is useful if you want to implement something like a
* toggle button.
*
*
* @param options {Object} Options:
* buttonCssClass: an extra CSS class to add to the menu button
* buttonImage: a url to the menu button image (default '../images/down.gif')
* @class Slick.Plugins.HeaderButtons
* @constructor
*/
function HeaderMenu(options) {
var _grid;
var _self = this;
var _handler = new Slick.EventHandler();
var _defaults = {
buttonCssClass: null,
buttonImage: null
};
var $menu;
var $activeHeaderColumn;
function init(grid) {
options = $.extend(true, {}, _defaults, options);
_grid = grid;
_handler
.subscribe(_grid.onHeaderCellRendered, handleHeaderCellRendered)
.subscribe(_grid.onBeforeHeaderCellDestroy, handleBeforeHeaderCellDestroy);
// Force the grid to re-render the header now that the events are hooked up.
_grid.setColumns(_grid.getColumns());
// Hide the menu on outside click.
$(document.body).bind("mousedown", handleBodyMouseDown);
}
function destroy() {
_handler.unsubscribeAll();
$(document.body).unbind("mousedown", handleBodyMouseDown);
}
function handleBodyMouseDown(e) {
if ($menu && $menu[0] != e.target && !$.contains($menu[0], e.target)) {
hideMenu();
}
}
function hideMenu() {
if ($menu) {
$menu.remove();
$menu = null;
$activeHeaderColumn
.removeClass("slick-header-column-active");
}
}
function handleHeaderCellRendered(e, args) {
var column = args.column;
var menu = column.header && column.header.menu;
if (menu) {
var $el = $("<div></div>")
.addClass("slick-header-menubutton")
.data("column", column)
.data("menu", menu);
if (options.buttonCssClass) {
$el.addClass(options.buttonCssClass);
}
if (options.buttonImage) {
$el.css("background-image", "url(" + options.buttonImage + ")");
}
if (menu.tooltip) {
$el.attr("title", menu.tooltip);
}
$el
.bind("click", showMenu)
.appendTo(args.node);
}
}
function handleBeforeHeaderCellDestroy(e, args) {
var column = args.column;
if (column.header && column.header.menu) {
$(args.node).find(".slick-header-menubutton").remove();
}
}
function showMenu(e) {
var $menuButton = $(this);
var menu = $menuButton.data("menu");
var columnDef = $menuButton.data("column");
// Let the user modify the menu or cancel altogether,
// or provide alternative menu implementation.
if (_self.onBeforeMenuShow.notify({
"grid": _grid,
"column": columnDef,
"menu": menu
}, e, _self) == false) {
return;
}
if (!$menu) {
$menu = $("<div class='slick-header-menu'></div>")
.appendTo(_grid.getContainerNode());
}
$menu.empty();
// Construct the menu items.
for (var i = 0; i < menu.items.length; i++) {
var item = menu.items[i];
var $li = $("<div class='slick-header-menuitem'></div>")
.data("command", item.command || '')
.data("column", columnDef)
.data("item", item)
.bind("click", handleMenuItemClick)
.appendTo($menu);
if (item.disabled) {
$li.addClass("slick-header-menuitem-disabled");
}
if (item.tooltip) {
$li.attr("title", item.tooltip);
}
var $icon = $("<div class='slick-header-menuicon'></div>")
.appendTo($li);
if (item.iconCssClass) {
$icon.addClass(item.iconCssClass);
}
if (item.iconImage) {
$icon.css("background-image", "url(" + item.iconImage + ")");
}
$("<span class='slick-header-menucontent'></span>")
.text(item.title)
.appendTo($li);
}
// Position the menu.
$menu
.offset({ top: $(this).offset().top + $(this).height(), left: $(this).offset().left });
// Mark the header as active to keep the highlighting.
$activeHeaderColumn = $menuButton.closest(".slick-header-column");
$activeHeaderColumn
.addClass("slick-header-column-active");
// Stop propagation so that it doesn't register as a header click event.
e.preventDefault();
e.stopPropagation();
}
function handleMenuItemClick(e) {
var command = $(this).data("command");
var columnDef = $(this).data("column");
var item = $(this).data("item");
if (item.disabled) {
return;
}
hideMenu();
if (command != null && command != '') {
_self.onCommand.notify({
"grid": _grid,
"column": columnDef,
"command": command,
"item": item
}, e, _self);
}
// Stop propagation so that it doesn't register as a header click event.
e.preventDefault();
e.stopPropagation();
}
$.extend(this, {
"init": init,
"destroy": destroy,
"onBeforeMenuShow": new Slick.Event(),
"onCommand": new Slick.Event()
});
}
})(jQuery);

View File

@ -0,0 +1,138 @@
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"RowMoveManager": RowMoveManager
}
});
function RowMoveManager(options) {
var _grid;
var _canvas;
var _dragging;
var _self = this;
var _handler = new Slick.EventHandler();
var _defaults = {
cancelEditOnDrag: false
};
function init(grid) {
options = $.extend(true, {}, _defaults, options);
_grid = grid;
_canvas = _grid.getCanvasNode();
_handler
.subscribe(_grid.onDragInit, handleDragInit)
.subscribe(_grid.onDragStart, handleDragStart)
.subscribe(_grid.onDrag, handleDrag)
.subscribe(_grid.onDragEnd, handleDragEnd);
}
function destroy() {
_handler.unsubscribeAll();
}
function handleDragInit(e, dd) {
// prevent the grid from cancelling drag'n'drop by default
e.stopImmediatePropagation();
}
function handleDragStart(e, dd) {
var cell = _grid.getCellFromEvent(e);
if (options.cancelEditOnDrag && _grid.getEditorLock().isActive()) {
_grid.getEditorLock().cancelCurrentEdit();
}
if (_grid.getEditorLock().isActive() || !/move|selectAndMove/.test(_grid.getColumns()[cell.cell].behavior)) {
return false;
}
_dragging = true;
e.stopImmediatePropagation();
var selectedRows = _grid.getSelectedRows();
if (selectedRows.length == 0 || $.inArray(cell.row, selectedRows) == -1) {
selectedRows = [cell.row];
_grid.setSelectedRows(selectedRows);
}
var rowHeight = _grid.getOptions().rowHeight;
dd.selectedRows = selectedRows;
dd.selectionProxy = $("<div class='slick-reorder-proxy'/>")
.css("position", "absolute")
.css("zIndex", "99999")
.css("width", $(_canvas).innerWidth())
.css("height", rowHeight * selectedRows.length)
.appendTo(_canvas);
dd.guide = $("<div class='slick-reorder-guide'/>")
.css("position", "absolute")
.css("zIndex", "99998")
.css("width", $(_canvas).innerWidth())
.css("top", -1000)
.appendTo(_canvas);
dd.insertBefore = -1;
}
function handleDrag(e, dd) {
if (!_dragging) {
return;
}
e.stopImmediatePropagation();
var top = e.pageY - $(_canvas).offset().top;
dd.selectionProxy.css("top", top - 5);
var insertBefore = Math.max(0, Math.min(Math.round(top / _grid.getOptions().rowHeight), _grid.getDataLength()));
if (insertBefore !== dd.insertBefore) {
var eventData = {
"rows": dd.selectedRows,
"insertBefore": insertBefore
};
if (_self.onBeforeMoveRows.notify(eventData) === false) {
dd.guide.css("top", -1000);
dd.canMove = false;
} else {
dd.guide.css("top", insertBefore * _grid.getOptions().rowHeight);
dd.canMove = true;
}
dd.insertBefore = insertBefore;
}
}
function handleDragEnd(e, dd) {
if (!_dragging) {
return;
}
_dragging = false;
e.stopImmediatePropagation();
dd.guide.remove();
dd.selectionProxy.remove();
if (dd.canMove) {
var eventData = {
"rows": dd.selectedRows,
"insertBefore": dd.insertBefore
};
// TODO: _grid.remapCellCssClasses ?
_self.onMoveRows.notify(eventData);
}
}
$.extend(this, {
"onBeforeMoveRows": new Slick.Event(),
"onMoveRows": new Slick.Event(),
"init": init,
"destroy": destroy
});
}
})(jQuery);

View File

@ -0,0 +1,187 @@
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"RowSelectionModel": RowSelectionModel
}
});
function RowSelectionModel(options) {
var _grid;
var _ranges = [];
var _self = this;
var _handler = new Slick.EventHandler();
var _inHandler;
var _options;
var _defaults = {
selectActiveRow: true
};
function init(grid) {
_options = $.extend(true, {}, _defaults, options);
_grid = grid;
_handler.subscribe(_grid.onActiveCellChanged,
wrapHandler(handleActiveCellChange));
_handler.subscribe(_grid.onKeyDown,
wrapHandler(handleKeyDown));
_handler.subscribe(_grid.onClick,
wrapHandler(handleClick));
}
function destroy() {
_handler.unsubscribeAll();
}
function wrapHandler(handler) {
return function () {
if (!_inHandler) {
_inHandler = true;
handler.apply(this, arguments);
_inHandler = false;
}
};
}
function rangesToRows(ranges) {
var rows = [];
for (var i = 0; i < ranges.length; i++) {
for (var j = ranges[i].fromRow; j <= ranges[i].toRow; j++) {
rows.push(j);
}
}
return rows;
}
function rowsToRanges(rows) {
var ranges = [];
var lastCell = _grid.getColumns().length - 1;
for (var i = 0; i < rows.length; i++) {
ranges.push(new Slick.Range(rows[i], 0, rows[i], lastCell));
}
return ranges;
}
function getRowsRange(from, to) {
var i, rows = [];
for (i = from; i <= to; i++) {
rows.push(i);
}
for (i = to; i < from; i++) {
rows.push(i);
}
return rows;
}
function getSelectedRows() {
return rangesToRows(_ranges);
}
function setSelectedRows(rows) {
setSelectedRanges(rowsToRanges(rows));
}
function setSelectedRanges(ranges) {
_ranges = ranges;
_self.onSelectedRangesChanged.notify(_ranges);
}
function getSelectedRanges() {
return _ranges;
}
function handleActiveCellChange(e, data) {
if (_options.selectActiveRow && data.row != null) {
setSelectedRanges([new Slick.Range(data.row, 0, data.row, _grid.getColumns().length - 1)]);
}
}
function handleKeyDown(e) {
var activeRow = _grid.getActiveCell();
if (activeRow && e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey && (e.which == 38 || e.which == 40)) {
var selectedRows = getSelectedRows();
selectedRows.sort(function (x, y) {
return x - y
});
if (!selectedRows.length) {
selectedRows = [activeRow.row];
}
var top = selectedRows[0];
var bottom = selectedRows[selectedRows.length - 1];
var active;
if (e.which == 40) {
active = activeRow.row < bottom || top == bottom ? ++bottom : ++top;
} else {
active = activeRow.row < bottom ? --bottom : --top;
}
if (active >= 0 && active < _grid.getDataLength()) {
_grid.scrollRowIntoView(active);
_ranges = rowsToRanges(getRowsRange(top, bottom));
setSelectedRanges(_ranges);
}
e.preventDefault();
e.stopPropagation();
}
}
function handleClick(e) {
var cell = _grid.getCellFromEvent(e);
if (!cell || !_grid.canCellBeActive(cell.row, cell.cell)) {
return false;
}
if (!_grid.getOptions().multiSelect || (
!e.ctrlKey && !e.shiftKey && !e.metaKey)) {
return false;
}
var selection = rangesToRows(_ranges);
var idx = $.inArray(cell.row, selection);
if (idx === -1 && (e.ctrlKey || e.metaKey)) {
selection.push(cell.row);
_grid.setActiveCell(cell.row, cell.cell);
} else if (idx !== -1 && (e.ctrlKey || e.metaKey)) {
selection = $.grep(selection, function (o, i) {
return (o !== cell.row);
});
_grid.setActiveCell(cell.row, cell.cell);
} else if (selection.length && e.shiftKey) {
var last = selection.pop();
var from = Math.min(cell.row, last);
var to = Math.max(cell.row, last);
selection = [];
for (var i = from; i <= to; i++) {
if (i !== last) {
selection.push(i);
}
}
selection.push(last);
_grid.setActiveCell(cell.row, cell.cell);
}
_ranges = rowsToRanges(selection);
setSelectedRanges(_ranges);
e.stopImmediatePropagation();
return true;
}
$.extend(this, {
"getSelectedRows": getSelectedRows,
"setSelectedRows": setSelectedRows,
"getSelectedRanges": getSelectedRanges,
"setSelectedRanges": setSelectedRanges,
"init": init,
"destroy": destroy,
"onSelectedRangesChanged": new Slick.Event()
});
}
})(jQuery);

View File

@ -0,0 +1,118 @@
/*
IMPORTANT:
In order to preserve the uniform grid appearance, all cell styles need to have padding, margin and border sizes.
No built-in (selected, editable, highlight, flashing, invalid, loading, :focus) or user-specified CSS
classes should alter those!
*/
.slick-header-columns {
background: url('images/header-columns-bg.gif') repeat-x center bottom;
border-bottom: 1px solid silver;
}
.slick-header-column {
background: url('images/header-columns-bg.gif') repeat-x center bottom;
border-right: 1px solid silver;
}
.slick-header-column:hover, .slick-header-column-active {
background: white url('images/header-columns-over-bg.gif') repeat-x center bottom;
}
.slick-headerrow {
background: #fafafa;
}
.slick-headerrow-column {
background: #fafafa;
border-bottom: 0;
height: 100%;
}
.slick-row.ui-state-active {
background: #F5F7D7;
}
.slick-row {
position: absolute;
background: white;
border: 0px;
line-height: 20px;
}
.slick-row.selected {
z-index: 10;
background: #DFE8F6;
}
.slick-cell {
padding-left: 4px;
padding-right: 4px;
}
.slick-group {
border-bottom: 2px solid silver;
}
.slick-group-toggle {
width: 9px;
height: 9px;
margin-right: 5px;
}
.slick-group-toggle.expanded {
background: url(images/collapse.gif) no-repeat center center;
}
.slick-group-toggle.collapsed {
background: url(images/expand.gif) no-repeat center center;
}
.slick-group-totals {
color: gray;
background: white;
}
.slick-cell.selected {
background-color: beige;
}
.slick-cell.active {
border-color: gray;
border-style: solid;
}
.slick-sortable-placeholder {
background: silver !important;
}
.slick-row.odd {
background: #fafafa;
}
.slick-row.ui-state-active {
background: #F5F7D7;
}
.slick-row.loading {
opacity: 0.5;
filter: alpha(opacity = 50);
}
.slick-cell.invalid {
border-color: red;
-moz-animation-duration: 0.2s;
-webkit-animation-duration: 0.2s;
-moz-animation-name: slickgrid-invalid-hilite;
-webkit-animation-name: slickgrid-invalid-hilite;
}
@-moz-keyframes slickgrid-invalid-hilite {
from { box-shadow: 0 0 6px red; }
to { box-shadow: none; }
}
@-webkit-keyframes slickgrid-invalid-hilite {
from { box-shadow: 0 0 6px red; }
to { box-shadow: none; }
}

View File

@ -0,0 +1,467 @@
/***
* Contains core SlickGrid classes.
* @module Core
* @namespace Slick
*/
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"Event": Event,
"EventData": EventData,
"EventHandler": EventHandler,
"Range": Range,
"NonDataRow": NonDataItem,
"Group": Group,
"GroupTotals": GroupTotals,
"EditorLock": EditorLock,
/***
* A global singleton editor lock.
* @class GlobalEditorLock
* @static
* @constructor
*/
"GlobalEditorLock": new EditorLock()
}
});
/***
* An event object for passing data to event handlers and letting them control propagation.
* <p>This is pretty much identical to how W3C and jQuery implement events.</p>
* @class EventData
* @constructor
*/
function EventData() {
var isPropagationStopped = false;
var isImmediatePropagationStopped = false;
/***
* Stops event from propagating up the DOM tree.
* @method stopPropagation
*/
this.stopPropagation = function () {
isPropagationStopped = true;
};
/***
* Returns whether stopPropagation was called on this event object.
* @method isPropagationStopped
* @return {Boolean}
*/
this.isPropagationStopped = function () {
return isPropagationStopped;
};
/***
* Prevents the rest of the handlers from being executed.
* @method stopImmediatePropagation
*/
this.stopImmediatePropagation = function () {
isImmediatePropagationStopped = true;
};
/***
* Returns whether stopImmediatePropagation was called on this event object.\
* @method isImmediatePropagationStopped
* @return {Boolean}
*/
this.isImmediatePropagationStopped = function () {
return isImmediatePropagationStopped;
}
}
/***
* A simple publisher-subscriber implementation.
* @class Event
* @constructor
*/
function Event() {
var handlers = [];
/***
* Adds an event handler to be called when the event is fired.
* <p>Event handler will receive two arguments - an <code>EventData</code> and the <code>data</code>
* object the event was fired with.<p>
* @method subscribe
* @param fn {Function} Event handler.
*/
this.subscribe = function (fn) {
handlers.push(fn);
};
/***
* Removes an event handler added with <code>subscribe(fn)</code>.
* @method unsubscribe
* @param fn {Function} Event handler to be removed.
*/
this.unsubscribe = function (fn) {
for (var i = handlers.length - 1; i >= 0; i--) {
if (handlers[i] === fn) {
handlers.splice(i, 1);
}
}
};
/***
* Fires an event notifying all subscribers.
* @method notify
* @param args {Object} Additional data object to be passed to all handlers.
* @param e {EventData}
* Optional.
* An <code>EventData</code> object to be passed to all handlers.
* For DOM events, an existing W3C/jQuery event object can be passed in.
* @param scope {Object}
* Optional.
* The scope ("this") within which the handler will be executed.
* If not specified, the scope will be set to the <code>Event</code> instance.
*/
this.notify = function (args, e, scope) {
e = e || new EventData();
scope = scope || this;
var returnValue;
for (var i = 0; i < handlers.length && !(e.isPropagationStopped() || e.isImmediatePropagationStopped()); i++) {
returnValue = handlers[i].call(scope, e, args);
}
return returnValue;
};
}
function EventHandler() {
var handlers = [];
this.subscribe = function (event, handler) {
handlers.push({
event: event,
handler: handler
});
event.subscribe(handler);
return this; // allow chaining
};
this.unsubscribe = function (event, handler) {
var i = handlers.length;
while (i--) {
if (handlers[i].event === event &&
handlers[i].handler === handler) {
handlers.splice(i, 1);
event.unsubscribe(handler);
return;
}
}
return this; // allow chaining
};
this.unsubscribeAll = function () {
var i = handlers.length;
while (i--) {
handlers[i].event.unsubscribe(handlers[i].handler);
}
handlers = [];
return this; // allow chaining
}
}
/***
* A structure containing a range of cells.
* @class Range
* @constructor
* @param fromRow {Integer} Starting row.
* @param fromCell {Integer} Starting cell.
* @param toRow {Integer} Optional. Ending row. Defaults to <code>fromRow</code>.
* @param toCell {Integer} Optional. Ending cell. Defaults to <code>fromCell</code>.
*/
function Range(fromRow, fromCell, toRow, toCell) {
if (toRow === undefined && toCell === undefined) {
toRow = fromRow;
toCell = fromCell;
}
/***
* @property fromRow
* @type {Integer}
*/
this.fromRow = Math.min(fromRow, toRow);
/***
* @property fromCell
* @type {Integer}
*/
this.fromCell = Math.min(fromCell, toCell);
/***
* @property toRow
* @type {Integer}
*/
this.toRow = Math.max(fromRow, toRow);
/***
* @property toCell
* @type {Integer}
*/
this.toCell = Math.max(fromCell, toCell);
/***
* Returns whether a range represents a single row.
* @method isSingleRow
* @return {Boolean}
*/
this.isSingleRow = function () {
return this.fromRow == this.toRow;
};
/***
* Returns whether a range represents a single cell.
* @method isSingleCell
* @return {Boolean}
*/
this.isSingleCell = function () {
return this.fromRow == this.toRow && this.fromCell == this.toCell;
};
/***
* Returns whether a range contains a given cell.
* @method contains
* @param row {Integer}
* @param cell {Integer}
* @return {Boolean}
*/
this.contains = function (row, cell) {
return row >= this.fromRow && row <= this.toRow &&
cell >= this.fromCell && cell <= this.toCell;
};
/***
* Returns a readable representation of a range.
* @method toString
* @return {String}
*/
this.toString = function () {
if (this.isSingleCell()) {
return "(" + this.fromRow + ":" + this.fromCell + ")";
}
else {
return "(" + this.fromRow + ":" + this.fromCell + " - " + this.toRow + ":" + this.toCell + ")";
}
}
}
/***
* A base class that all special / non-data rows (like Group and GroupTotals) derive from.
* @class NonDataItem
* @constructor
*/
function NonDataItem() {
this.__nonDataRow = true;
}
/***
* Information about a group of rows.
* @class Group
* @extends Slick.NonDataItem
* @constructor
*/
function Group() {
this.__group = true;
/**
* Grouping level, starting with 0.
* @property level
* @type {Number}
*/
this.level = 0;
/***
* Number of rows in the group.
* @property count
* @type {Integer}
*/
this.count = 0;
/***
* Grouping value.
* @property value
* @type {Object}
*/
this.value = null;
/***
* Formatted display value of the group.
* @property title
* @type {String}
*/
this.title = null;
/***
* Whether a group is collapsed.
* @property collapsed
* @type {Boolean}
*/
this.collapsed = false;
/***
* GroupTotals, if any.
* @property totals
* @type {GroupTotals}
*/
this.totals = null;
/**
* Rows that are part of the group.
* @property rows
* @type {Array}
*/
this.rows = [];
/**
* Sub-groups that are part of the group.
* @property groups
* @type {Array}
*/
this.groups = null;
/**
* A unique key used to identify the group. This key can be used in calls to DataView
* collapseGroup() or expandGroup().
* @property groupingKey
* @type {Object}
*/
this.groupingKey = null;
}
Group.prototype = new NonDataItem();
/***
* Compares two Group instances.
* @method equals
* @return {Boolean}
* @param group {Group} Group instance to compare to.
*/
Group.prototype.equals = function (group) {
return this.value === group.value &&
this.count === group.count &&
this.collapsed === group.collapsed &&
this.title === group.title;
};
/***
* Information about group totals.
* An instance of GroupTotals will be created for each totals row and passed to the aggregators
* so that they can store arbitrary data in it. That data can later be accessed by group totals
* formatters during the display.
* @class GroupTotals
* @extends Slick.NonDataItem
* @constructor
*/
function GroupTotals() {
this.__groupTotals = true;
/***
* Parent Group.
* @param group
* @type {Group}
*/
this.group = null;
/***
* Whether the totals have been fully initialized / calculated.
* Will be set to false for lazy-calculated group totals.
* @param initialized
* @type {Boolean}
*/
this.initialized = false;
}
GroupTotals.prototype = new NonDataItem();
/***
* A locking helper to track the active edit controller and ensure that only a single controller
* can be active at a time. This prevents a whole class of state and validation synchronization
* issues. An edit controller (such as SlickGrid) can query if an active edit is in progress
* and attempt a commit or cancel before proceeding.
* @class EditorLock
* @constructor
*/
function EditorLock() {
var activeEditController = null;
/***
* Returns true if a specified edit controller is active (has the edit lock).
* If the parameter is not specified, returns true if any edit controller is active.
* @method isActive
* @param editController {EditController}
* @return {Boolean}
*/
this.isActive = function (editController) {
return (editController ? activeEditController === editController : activeEditController !== null);
};
/***
* Sets the specified edit controller as the active edit controller (acquire edit lock).
* If another edit controller is already active, and exception will be thrown.
* @method activate
* @param editController {EditController} edit controller acquiring the lock
*/
this.activate = function (editController) {
if (editController === activeEditController) { // already activated?
return;
}
if (activeEditController !== null) {
throw "SlickGrid.EditorLock.activate: an editController is still active, can't activate another editController";
}
if (!editController.commitCurrentEdit) {
throw "SlickGrid.EditorLock.activate: editController must implement .commitCurrentEdit()";
}
if (!editController.cancelCurrentEdit) {
throw "SlickGrid.EditorLock.activate: editController must implement .cancelCurrentEdit()";
}
activeEditController = editController;
};
/***
* Unsets the specified edit controller as the active edit controller (release edit lock).
* If the specified edit controller is not the active one, an exception will be thrown.
* @method deactivate
* @param editController {EditController} edit controller releasing the lock
*/
this.deactivate = function (editController) {
if (activeEditController !== editController) {
throw "SlickGrid.EditorLock.deactivate: specified editController is not the currently active one";
}
activeEditController = null;
};
/***
* Attempts to commit the current edit by calling "commitCurrentEdit" method on the active edit
* controller and returns whether the commit attempt was successful (commit may fail due to validation
* errors, etc.). Edit controller's "commitCurrentEdit" must return true if the commit has succeeded
* and false otherwise. If no edit controller is active, returns true.
* @method commitCurrentEdit
* @return {Boolean}
*/
this.commitCurrentEdit = function () {
return (activeEditController ? activeEditController.commitCurrentEdit() : true);
};
/***
* Attempts to cancel the current edit by calling "cancelCurrentEdit" method on the active edit
* controller and returns whether the edit was successfully cancelled. If no edit controller is
* active, returns true.
* @method cancelCurrentEdit
* @return {Boolean}
*/
this.cancelCurrentEdit = function cancelCurrentEdit() {
return (activeEditController ? activeEditController.cancelCurrentEdit() : true);
};
}
})(jQuery);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,512 @@
/***
* Contains basic SlickGrid editors.
* @module Editors
* @namespace Slick
*/
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"Editors": {
"Text": TextEditor,
"Integer": IntegerEditor,
"Date": DateEditor,
"YesNoSelect": YesNoSelectEditor,
"Checkbox": CheckboxEditor,
"PercentComplete": PercentCompleteEditor,
"LongText": LongTextEditor
}
}
});
function TextEditor(args) {
var $input;
var defaultValue;
var scope = this;
this.init = function () {
$input = $("<INPUT type=text class='editor-text' />")
.appendTo(args.container)
.bind("keydown.nav", function (e) {
if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT) {
e.stopImmediatePropagation();
}
})
.focus()
.select();
};
this.destroy = function () {
$input.remove();
};
this.focus = function () {
$input.focus();
};
this.getValue = function () {
return $input.val();
};
this.setValue = function (val) {
$input.val(val);
};
this.loadValue = function (item) {
defaultValue = item[args.column.field] || "";
$input.val(defaultValue);
$input[0].defaultValue = defaultValue;
$input.select();
};
this.serializeValue = function () {
return $input.val();
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
};
this.validate = function () {
if (args.column.validator) {
var validationResults = args.column.validator($input.val());
if (!validationResults.valid) {
return validationResults;
}
}
return {
valid: true,
msg: null
};
};
this.init();
}
function IntegerEditor(args) {
var $input;
var defaultValue;
var scope = this;
this.init = function () {
$input = $("<INPUT type=text class='editor-text' />");
$input.bind("keydown.nav", function (e) {
if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT) {
e.stopImmediatePropagation();
}
});
$input.appendTo(args.container);
$input.focus().select();
};
this.destroy = function () {
$input.remove();
};
this.focus = function () {
$input.focus();
};
this.loadValue = function (item) {
defaultValue = item[args.column.field];
$input.val(defaultValue);
$input[0].defaultValue = defaultValue;
$input.select();
};
this.serializeValue = function () {
return parseInt($input.val(), 10) || 0;
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
};
this.validate = function () {
if (isNaN($input.val())) {
return {
valid: false,
msg: "Please enter a valid integer"
};
}
return {
valid: true,
msg: null
};
};
this.init();
}
function DateEditor(args) {
var $input;
var defaultValue;
var scope = this;
var calendarOpen = false;
this.init = function () {
$input = $("<INPUT type=text class='editor-text' />");
$input.appendTo(args.container);
$input.focus().select();
$input.datepicker({
showOn: "button",
buttonImageOnly: true,
buttonImage: "../images/calendar.gif",
beforeShow: function () {
calendarOpen = true
},
onClose: function () {
calendarOpen = false
}
});
$input.width($input.width() - 18);
};
this.destroy = function () {
$.datepicker.dpDiv.stop(true, true);
$input.datepicker("hide");
$input.datepicker("destroy");
$input.remove();
};
this.show = function () {
if (calendarOpen) {
$.datepicker.dpDiv.stop(true, true).show();
}
};
this.hide = function () {
if (calendarOpen) {
$.datepicker.dpDiv.stop(true, true).hide();
}
};
this.position = function (position) {
if (!calendarOpen) {
return;
}
$.datepicker.dpDiv
.css("top", position.top + 30)
.css("left", position.left);
};
this.focus = function () {
$input.focus();
};
this.loadValue = function (item) {
defaultValue = item[args.column.field];
$input.val(defaultValue);
$input[0].defaultValue = defaultValue;
$input.select();
};
this.serializeValue = function () {
return $input.val();
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
};
this.validate = function () {
return {
valid: true,
msg: null
};
};
this.init();
}
function YesNoSelectEditor(args) {
var $select;
var defaultValue;
var scope = this;
this.init = function () {
$select = $("<SELECT tabIndex='0' class='editor-yesno'><OPTION value='yes'>Yes</OPTION><OPTION value='no'>No</OPTION></SELECT>");
$select.appendTo(args.container);
$select.focus();
};
this.destroy = function () {
$select.remove();
};
this.focus = function () {
$select.focus();
};
this.loadValue = function (item) {
$select.val((defaultValue = item[args.column.field]) ? "yes" : "no");
$select.select();
};
this.serializeValue = function () {
return ($select.val() == "yes");
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return ($select.val() != defaultValue);
};
this.validate = function () {
return {
valid: true,
msg: null
};
};
this.init();
}
function CheckboxEditor(args) {
var $select;
var defaultValue;
var scope = this;
this.init = function () {
$select = $("<INPUT type=checkbox value='true' class='editor-checkbox' hideFocus>");
$select.appendTo(args.container);
$select.focus();
};
this.destroy = function () {
$select.remove();
};
this.focus = function () {
$select.focus();
};
this.loadValue = function (item) {
defaultValue = !!item[args.column.field];
if (defaultValue) {
$select.prop('checked', true);
} else {
$select.prop('checked', false);
}
};
this.serializeValue = function () {
return $select.prop('checked');
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return (this.serializeValue() !== defaultValue);
};
this.validate = function () {
return {
valid: true,
msg: null
};
};
this.init();
}
function PercentCompleteEditor(args) {
var $input, $picker;
var defaultValue;
var scope = this;
this.init = function () {
$input = $("<INPUT type=text class='editor-percentcomplete' />");
$input.width($(args.container).innerWidth() - 25);
$input.appendTo(args.container);
$picker = $("<div class='editor-percentcomplete-picker' />").appendTo(args.container);
$picker.append("<div class='editor-percentcomplete-helper'><div class='editor-percentcomplete-wrapper'><div class='editor-percentcomplete-slider' /><div class='editor-percentcomplete-buttons' /></div></div>");
$picker.find(".editor-percentcomplete-buttons").append("<button val=0>Not started</button><br/><button val=50>In Progress</button><br/><button val=100>Complete</button>");
$input.focus().select();
$picker.find(".editor-percentcomplete-slider").slider({
orientation: "vertical",
range: "min",
value: defaultValue,
slide: function (event, ui) {
$input.val(ui.value)
}
});
$picker.find(".editor-percentcomplete-buttons button").bind("click", function (e) {
$input.val($(this).attr("val"));
$picker.find(".editor-percentcomplete-slider").slider("value", $(this).attr("val"));
})
};
this.destroy = function () {
$input.remove();
$picker.remove();
};
this.focus = function () {
$input.focus();
};
this.loadValue = function (item) {
$input.val(defaultValue = item[args.column.field]);
$input.select();
};
this.serializeValue = function () {
return parseInt($input.val(), 10) || 0;
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return (!($input.val() == "" && defaultValue == null)) && ((parseInt($input.val(), 10) || 0) != defaultValue);
};
this.validate = function () {
if (isNaN(parseInt($input.val(), 10))) {
return {
valid: false,
msg: "Please enter a valid positive number"
};
}
return {
valid: true,
msg: null
};
};
this.init();
}
/*
* An example of a "detached" editor.
* The UI is added onto document BODY and .position(), .show() and .hide() are implemented.
* KeyDown events are also handled to provide handling for Tab, Shift-Tab, Esc and Ctrl-Enter.
*/
function LongTextEditor(args) {
var $input, $wrapper;
var defaultValue;
var scope = this;
this.init = function () {
var $container = $("body");
$wrapper = $("<DIV style='z-index:10000;position:absolute;background:white;padding:5px;border:3px solid gray; -moz-border-radius:10px; border-radius:10px;'/>")
.appendTo($container);
$input = $("<TEXTAREA hidefocus rows=5 style='backround:white;width:250px;height:80px;border:0;outline:0'>")
.appendTo($wrapper);
$("<DIV style='text-align:right'><BUTTON>Save</BUTTON><BUTTON>Cancel</BUTTON></DIV>")
.appendTo($wrapper);
$wrapper.find("button:first").bind("click", this.save);
$wrapper.find("button:last").bind("click", this.cancel);
$input.bind("keydown", this.handleKeyDown);
scope.position(args.position);
$input.focus().select();
};
this.handleKeyDown = function (e) {
if (e.which == $.ui.keyCode.ENTER && e.ctrlKey) {
scope.save();
} else if (e.which == $.ui.keyCode.ESCAPE) {
e.preventDefault();
scope.cancel();
} else if (e.which == $.ui.keyCode.TAB && e.shiftKey) {
e.preventDefault();
args.grid.navigatePrev();
} else if (e.which == $.ui.keyCode.TAB) {
e.preventDefault();
args.grid.navigateNext();
}
};
this.save = function () {
args.commitChanges();
};
this.cancel = function () {
$input.val(defaultValue);
args.cancelChanges();
};
this.hide = function () {
$wrapper.hide();
};
this.show = function () {
$wrapper.show();
};
this.position = function (position) {
$wrapper
.css("top", position.top - 5)
.css("left", position.left - 5)
};
this.destroy = function () {
$wrapper.remove();
};
this.focus = function () {
$input.focus();
};
this.loadValue = function (item) {
$input.val(defaultValue = item[args.column.field]);
$input.select();
};
this.serializeValue = function () {
return $input.val();
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
};
this.validate = function () {
return {
valid: true,
msg: null
};
};
this.init();
}
})(jQuery);

View File

@ -0,0 +1,59 @@
/***
* Contains basic SlickGrid formatters.
*
* NOTE: These are merely examples. You will most likely need to implement something more
* robust/extensible/localizable/etc. for your use!
*
* @module Formatters
* @namespace Slick
*/
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"Formatters": {
"PercentComplete": PercentCompleteFormatter,
"PercentCompleteBar": PercentCompleteBarFormatter,
"YesNo": YesNoFormatter,
"Checkmark": CheckmarkFormatter
}
}
});
function PercentCompleteFormatter(row, cell, value, columnDef, dataContext) {
if (value == null || value === "") {
return "-";
} else if (value < 50) {
return "<span style='color:red;font-weight:bold;'>" + value + "%</span>";
} else {
return "<span style='color:green'>" + value + "%</span>";
}
}
function PercentCompleteBarFormatter(row, cell, value, columnDef, dataContext) {
if (value == null || value === "") {
return "";
}
var color;
if (value < 30) {
color = "red";
} else if (value < 70) {
color = "silver";
} else {
color = "green";
}
return "<span class='percent-complete-bar' style='background:" + color + ";width:" + value + "%'></span>";
}
function YesNoFormatter(row, cell, value, columnDef, dataContext) {
return value ? "Yes" : "No";
}
function CheckmarkFormatter(row, cell, value, columnDef, dataContext) {
return value ? "<img src='../images/tick.png'>" : "";
}
})(jQuery);

View File

@ -0,0 +1,157 @@
/*
IMPORTANT:
In order to preserve the uniform grid appearance, all cell styles need to have padding, margin and border sizes.
No built-in (selected, editable, highlight, flashing, invalid, loading, :focus) or user-specified CSS
classes should alter those!
*/
.slick-header.ui-state-default, .slick-headerrow.ui-state-default {
width: 100%;
overflow: hidden;
border-left: 0px;
}
.slick-header-columns, .slick-headerrow-columns {
position: relative;
white-space: nowrap;
cursor: default;
overflow: hidden;
}
.slick-header-column.ui-state-default {
position: relative;
display: inline-block;
overflow: hidden;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
height: 16px;
line-height: 16px;
margin: 0;
padding: 4px;
border-right: 1px solid silver;
border-left: 0px;
border-top: 0px;
border-bottom: 0px;
float: left;
}
.slick-headerrow-column.ui-state-default {
padding: 4px;
}
.slick-header-column-sorted {
font-style: italic;
}
.slick-sort-indicator {
display: inline-block;
width: 8px;
height: 5px;
margin-left: 4px;
margin-top: 6px;
float: left;
}
.slick-sort-indicator-desc {
background: url(images/sort-desc.gif);
}
.slick-sort-indicator-asc {
background: url(images/sort-asc.gif);
}
.slick-resizable-handle {
position: absolute;
font-size: 0.1px;
display: block;
cursor: col-resize;
width: 4px;
right: 0px;
top: 0;
height: 100%;
}
.slick-sortable-placeholder {
background: silver;
}
.grid-canvas {
position: relative;
outline: 0;
}
.slick-row.ui-widget-content, .slick-row.ui-state-active {
position: absolute;
border: 0px;
width: 100%;
}
.slick-cell, .slick-headerrow-column {
position: absolute;
border: 1px solid transparent;
border-right: 1px dotted silver;
border-bottom-color: silver;
overflow: hidden;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
vertical-align: middle;
z-index: 1;
padding: 1px 2px 2px 1px;
margin: 0;
white-space: nowrap;
cursor: default;
}
.slick-group {
}
.slick-group-toggle {
display: inline-block;
}
.slick-cell.highlighted {
background: lightskyblue;
background: rgba(0, 0, 255, 0.2);
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
.slick-cell.flashing {
border: 1px solid red !important;
}
.slick-cell.editable {
z-index: 11;
overflow: visible;
background: white;
border-color: black;
border-style: solid;
}
.slick-cell:focus {
outline: none;
}
.slick-reorder-proxy {
display: inline-block;
background: blue;
opacity: 0.15;
filter: alpha(opacity = 15);
cursor: move;
}
.slick-reorder-guide {
display: inline-block;
height: 2px;
background: blue;
opacity: 0.7;
filter: alpha(opacity = 70);
}
.slick-selection {
z-index: 10;
position: absolute;
border: 2px dashed black;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,158 @@
(function ($) {
$.extend(true, window, {
Slick: {
Data: {
GroupItemMetadataProvider: GroupItemMetadataProvider
}
}
});
/***
* Provides item metadata for group (Slick.Group) and totals (Slick.Totals) rows produced by the DataView.
* This metadata overrides the default behavior and formatting of those rows so that they appear and function
* correctly when processed by the grid.
*
* This class also acts as a grid plugin providing event handlers to expand & collapse groups.
* If "grid.registerPlugin(...)" is not called, expand & collapse will not work.
*
* @class GroupItemMetadataProvider
* @module Data
* @namespace Slick.Data
* @constructor
* @param options
*/
function GroupItemMetadataProvider(options) {
var _grid;
var _defaults = {
groupCssClass: "slick-group",
groupTitleCssClass: "slick-group-title",
totalsCssClass: "slick-group-totals",
groupFocusable: true,
totalsFocusable: false,
toggleCssClass: "slick-group-toggle",
toggleExpandedCssClass: "expanded",
toggleCollapsedCssClass: "collapsed",
enableExpandCollapse: true,
groupFormatter: defaultGroupCellFormatter,
totalsFormatter: defaultTotalsCellFormatter
};
options = $.extend(true, {}, _defaults, options);
function defaultGroupCellFormatter(row, cell, value, columnDef, item) {
if (!options.enableExpandCollapse) {
return item.title;
}
var indentation = item.level * 15 + "px";
return "<span class='" + options.toggleCssClass + " " +
(item.collapsed ? options.toggleCollapsedCssClass : options.toggleExpandedCssClass) +
"' style='margin-left:" + indentation +"'>" +
"</span>" +
"<span class='" + options.groupTitleCssClass + "' level='" + item.level + "'>" +
item.title +
"</span>";
}
function defaultTotalsCellFormatter(row, cell, value, columnDef, item) {
return (columnDef.groupTotalsFormatter && columnDef.groupTotalsFormatter(item, columnDef)) || "";
}
function init(grid) {
_grid = grid;
_grid.onClick.subscribe(handleGridClick);
_grid.onKeyDown.subscribe(handleGridKeyDown);
}
function destroy() {
if (_grid) {
_grid.onClick.unsubscribe(handleGridClick);
_grid.onKeyDown.unsubscribe(handleGridKeyDown);
}
}
function handleGridClick(e, args) {
var item = this.getDataItem(args.row);
if (item && item instanceof Slick.Group && $(e.target).hasClass(options.toggleCssClass)) {
var range = _grid.getRenderedRange();
this.getData().setRefreshHints({
ignoreDiffsBefore: range.top,
ignoreDiffsAfter: range.bottom
});
if (item.collapsed) {
this.getData().expandGroup(item.groupingKey);
} else {
this.getData().collapseGroup(item.groupingKey);
}
e.stopImmediatePropagation();
e.preventDefault();
}
}
// TODO: add -/+ handling
function handleGridKeyDown(e, args) {
if (options.enableExpandCollapse && (e.which == $.ui.keyCode.SPACE)) {
var activeCell = this.getActiveCell();
if (activeCell) {
var item = this.getDataItem(activeCell.row);
if (item && item instanceof Slick.Group) {
var range = _grid.getRenderedRange();
this.getData().setRefreshHints({
ignoreDiffsBefore: range.top,
ignoreDiffsAfter: range.bottom
});
if (item.collapsed) {
this.getData().expandGroup(item.groupingKey);
} else {
this.getData().collapseGroup(item.groupingKey);
}
e.stopImmediatePropagation();
e.preventDefault();
}
}
}
}
function getGroupRowMetadata(item) {
return {
selectable: false,
focusable: options.groupFocusable,
cssClasses: options.groupCssClass,
columns: {
0: {
colspan: "*",
formatter: options.groupFormatter,
editor: null
}
}
};
}
function getTotalsRowMetadata(item) {
return {
selectable: false,
focusable: options.totalsFocusable,
cssClasses: options.totalsCssClass,
formatter: options.totalsFormatter,
editor: null
};
}
return {
"init": init,
"destroy": destroy,
"getGroupRowMetadata": getGroupRowMetadata,
"getTotalsRowMetadata": getTotalsRowMetadata
};
}
})(jQuery);

View File

@ -0,0 +1,173 @@
(function ($) {
/***
* A sample AJAX data store implementation.
* Right now, it's hooked up to load Hackernews stories, but can
* easily be extended to support any JSONP-compatible backend that accepts paging parameters.
*/
function RemoteModel() {
// private
var PAGESIZE = 50;
var data = {length: 0};
var searchstr = "";
var sortcol = null;
var sortdir = 1;
var h_request = null;
var req = null; // ajax request
// events
var onDataLoading = new Slick.Event();
var onDataLoaded = new Slick.Event();
function init() {
}
function isDataLoaded(from, to) {
for (var i = from; i <= to; i++) {
if (data[i] == undefined || data[i] == null) {
return false;
}
}
return true;
}
function clear() {
for (var key in data) {
delete data[key];
}
data.length = 0;
}
function ensureData(from, to) {
if (req) {
req.abort();
for (var i = req.fromPage; i <= req.toPage; i++)
data[i * PAGESIZE] = undefined;
}
if (from < 0) {
from = 0;
}
if (data.length > 0) {
to = Math.min(to, data.length - 1);
}
var fromPage = Math.floor(from / PAGESIZE);
var toPage = Math.floor(to / PAGESIZE);
while (data[fromPage * PAGESIZE] !== undefined && fromPage < toPage)
fromPage++;
while (data[toPage * PAGESIZE] !== undefined && fromPage < toPage)
toPage--;
if (fromPage > toPage || ((fromPage == toPage) && data[fromPage * PAGESIZE] !== undefined)) {
// TODO: look-ahead
onDataLoaded.notify({from: from, to: to});
return;
}
var url = "http://api.thriftdb.com/api.hnsearch.com/items/_search?filter[fields][type][]=submission&q=" + searchstr + "&start=" + (fromPage * PAGESIZE) + "&limit=" + (((toPage - fromPage) * PAGESIZE) + PAGESIZE);
if (sortcol != null) {
url += ("&sortby=" + sortcol + ((sortdir > 0) ? "+asc" : "+desc"));
}
if (h_request != null) {
clearTimeout(h_request);
}
h_request = setTimeout(function () {
for (var i = fromPage; i <= toPage; i++)
data[i * PAGESIZE] = null; // null indicates a 'requested but not available yet'
onDataLoading.notify({from: from, to: to});
req = $.jsonp({
url: url,
callbackParameter: "callback",
cache: true,
success: onSuccess,
error: function () {
onError(fromPage, toPage)
}
});
req.fromPage = fromPage;
req.toPage = toPage;
}, 50);
}
function onError(fromPage, toPage) {
alert("error loading pages " + fromPage + " to " + toPage);
}
function onSuccess(resp) {
var from = resp.request.start, to = from + resp.results.length;
data.length = Math.min(parseInt(resp.hits),1000); // limitation of the API
for (var i = 0; i < resp.results.length; i++) {
var item = resp.results[i].item;
// Old IE versions can't parse ISO dates, so change to universally-supported format.
item.create_ts = item.create_ts.replace(/^(\d+)-(\d+)-(\d+)T(\d+:\d+:\d+)Z$/, "$2/$3/$1 $4 UTC");
item.create_ts = new Date(item.create_ts);
data[from + i] = item;
data[from + i].index = from + i;
}
req = null;
onDataLoaded.notify({from: from, to: to});
}
function reloadData(from, to) {
for (var i = from; i <= to; i++)
delete data[i];
ensureData(from, to);
}
function setSort(column, dir) {
sortcol = column;
sortdir = dir;
clear();
}
function setSearch(str) {
searchstr = str;
clear();
}
init();
return {
// properties
"data": data,
// methods
"clear": clear,
"isDataLoaded": isDataLoaded,
"ensureData": ensureData,
"reloadData": reloadData,
"setSort": setSort,
"setSearch": setSearch,
// events
"onDataLoading": onDataLoading,
"onDataLoaded": onDataLoaded
};
}
// Slick.Data.RemoteModel
$.extend(true, window, { Slick: { Data: { RemoteModel: RemoteModel }}});
})(jQuery);

View File

@ -0,0 +1,354 @@
/*
Initialization for Tabulizer
by Dimitrios Mourloukos
*/
var grid;
var grid_data = [];
var grid_row_limit = 500;
var grid_column_limit = 100;
var grid_selected_range = new Object;
var options = {
editable: true,
enableAddRow: true,
enableCellNavigation: true,
asyncEditorLoading: false,
autoEdit: false
};
var columns = [
{
id: "selector",
name: "",
field: "num",
width: 30
}
];
function FormulaEditor(args) {
var _self = this;
var _editor = new Slick.Editors.Text(args);
var _selector;
jQuery.extend(this, _editor);
function init() {
// register a plugin to select a range and append it to the textbox
// since events are fired in reverse order (most recently added are executed first),
// this will override other plugins like moverows or selection model and will
// not require the grid to not be in the edit mode
_selector = new Slick.CellRangeSelector();
_selector.onCellRangeSelected.subscribe(_self.handleCellRangeSelected);
args.grid.registerPlugin(_selector);
}
this.destroy = function () {
_selector.onCellRangeSelected.unsubscribe(_self.handleCellRangeSelected);
grid.unregisterPlugin(_selector);
_editor.destroy();
};
this.handleCellRangeSelected = function (e, args) {
_editor.setValue(
_editor.getValue() +
grid.getColumns()[args.range.fromCell].name +
args.range.fromRow +
":" +
grid.getColumns()[args.range.toCell].name +
args.range.toRow
);
};
init();
}
function initGrid(data, grid_rows, grid_columns) {
for (var i = 0; i < grid_column_limit; i++) {
columns.push({
id: i,
name: "Col"+(i+1),
field: i,
width: 60,
editor: FormulaEditor
});
}
for (var i = 0; i < grid_row_limit; i++) {
var d = (grid_data[i] = {});
d["num"] = i+1;
}
grid = new Slick.Grid("#grid", grid_data, columns, options);
var selectionModel = new Slick.CellSelectionModel();
grid.setSelectionModel(selectionModel);
grid.registerPlugin(new Slick.AutoTooltips());
// set keyboard focus on the grid
grid.getCanvasNode().focus();
var copyManager = new Slick.CellCopyManager();
grid.registerPlugin(copyManager);
copyManager.onPasteCells.subscribe(function (e, args) {
if (args.from.length !== 1 || args.to.length !== 1) {
throw "This implementation only supports single range copy and paste operations";
}
var from = args.from[0];
var to = args.to[0];
var val;
// treat differently the cases where the destination area is a single cell or not
var to_range_length = (to.toRow - to.fromRow) + (to.toCell - to.fromCell);
var i, j, copy_data = [];
for (i = 0; i <= from.toRow - from.fromRow; i++) {
copy_data[i] = [];
for (j = 0; j <= from.toCell - from.fromCell; j++) {
copy_data[i][j] = grid_data[from.fromRow + i][columns[from.fromCell + j].field];
}
}
if (to_range_length == 0) {
for (i = 0; i <= from.toRow - from.fromRow; i++) {
for (j = 0; j <= from.toCell - from.fromCell; j++) {
grid_data[to.fromRow + i][columns[to.fromCell + j].field] = copy_data[i][j];
grid.invalidateRow(to.fromRow + i);
}
}
} else {
for (i = 0; i <= from.toRow - from.fromRow; i++) {
for (j = 0; j <= from.toCell - from.fromCell; j++) {
if (i <= to.toRow - to.fromRow && j <= to.toCell - to.fromCell) {
val = copy_data[i][j];
grid_data[to.fromRow + i][columns[to.fromCell + j].field] = val;
grid.invalidateRow(to.fromRow + i);
}
/*
if (i <= to.toRow - to.fromRow && j <= to.toCell - to.fromCell) {
val = grid_data[from.fromRow + i][columns[from.fromCell + j].field];
grid_data[to.fromRow + i][columns[to.fromCell + j].field] = val;
grid.invalidateRow(to.fromRow + i);
}
*/
}
}
}
grid.render();
});
grid.onAddNewRow.subscribe(function (e, args) {
var item = args.item;
var column = args.column;
grid.invalidateRow(grid_data.length);
grid_data.push(item);
grid.updateRowCount();
grid.render();
});
grid.onContextMenu.subscribe(function (e) {
e.preventDefault();
var cell = grid.getCellFromEvent(e);
jQuery("#gridContextMenu")
.data("row", cell.row)
.data("column", cell.cell)
.css("top", e.pageY)
.css("left", e.pageX)
.show();
jQuery("body").one("click", function (e) {
// finally, hide context menu
jQuery("#gridContextMenu").hide();
});
});
selectionModel.onSelectedRangesChanged.subscribe(function (e, args) {
if (args.length == 1) {
grid_selected_range.fromRow = args[0].fromRow;
grid_selected_range.toRow = args[0].toRow
grid_selected_range.fromColumn = args[0].fromCell-1;
grid_selected_range.toColumn = args[0].toCell-1;
grid_selected_range.active = 1;
} else {
grid_selected_range.active = 0;
}
});
grid.onKeyDown.subscribe( function (e, args) {
if ((e.which != 46) || e.ctrlKey) {
return false;
}
if (grid_selected_range) {
if (grid_selected_range.active) {
for (var i = grid_selected_range.fromRow; i <= grid_selected_range.toRow; i++) {
for (var j = grid_selected_range.fromColumn; j <= grid_selected_range.toColumn; j++) {
grid_data[i][j] = null;
}
grid.invalidateRow(i);
}
grid.render();
e.preventDefault();
}
}
});
}
function gridAddRow(row_id, direction) {
var i, j, d;
var row_add = grid_row_limit;
if (direction == 'above') {
if (row_id>=0) row_add = row_id; else row_add = 0;
} else {
if (row_id < grid_row_limit) row_add = row_id + 1; else row_add = grid_row_limit;
}
grid_row_limit++;
for (i = grid_row_limit; i> row_add; i--) {
d = (grid_data[i] = {});
d["num"] = i+1;
if (grid_data[i-1] != null) {
for (j=0;j<=grid_column_limit;j++) {
if (grid_data[i-1][j] !== 'undefined') {
d[j] = grid_data[i-1][j];
} else {
d[j] = null;
}
}
grid.invalidateRow(i);
}
}
d = (grid_data[row_add] = {});
d["num"] = row_add+1;
/*
for (j=1;j<=grid_column_limit;j++) {
d[j] = null;
}
*/
grid.invalidateRow(row_add);
grid.updateRowCount();
grid.render();
}
function gridAddColumn(column_id, direction) {
var i, j, d;
var column_add = grid_column_limit;
if (direction == 'before') {
if (column_id>0) column_add = column_id - 1; else column_add = 1;
} else {
if (column_id < grid_column_limit) column_add = column_id; else column_add = grid_column_limit;
}
grid_column_limit++;
for (i = 0; i< grid_row_limit; i++) {
if (grid_data[i] != null) {
d = grid_data[i];
for (j=grid_column_limit;j>column_add;j--) {
if (typeof grid_data[i][j-1] !== 'undefined') {
d[j] = grid_data[i][j-1];
} else {
d[j] = null;
}
}
d[column_add] = null;
for (j=0;j<column_add;j++) {
if (typeof grid_data[i][j] !== 'undefined') {
d[j] = grid_data[i][j];
} else {
d[j] = null;
}
}
grid.invalidateRow(i);
}
}
grid.updateRowCount();
grid.render();
}
function gridRemoveRow(row_id) {
var i, j, d;
if (row_id<0) return;
else if (row_id > grid_row_limit) return;
else remove_row = row_id;
for (i = remove_row; i < grid_row_limit; i++) {
d = (grid_data[i] = {});
d["num"] = i+1;
if (grid_data[i+1] != null) {
for (j=0;j<grid_column_limit;j++) {
if (grid_data[i+1][j] !== 'undefined') {
d[j] = grid_data[i+1][j];
} else {
d[j] = null;
}
}
grid.invalidateRow(i);
}
}
grid.updateRowCount();
grid.render();
}
function gridRemoveColumn(column_id) {
var i, j, d;
if (column_id<1) return;
else if (column_id > grid_column_limit) return;
else remove_column = column_id-1;
for (i = 0; i< grid_row_limit; i++) {
if (grid_data[i] != null) {
d = grid_data[i];
for (j=0;j<remove_column;j++) {
if (grid_data[i][j] !== 'undefined') {
d[j] = grid_data[i][j];
} else {
d[j] = null;
}
}
for (j=remove_column;j<grid_column_limit;j++) {
if (grid_data[i][j+1] !== 'undefined') {
d[j] = grid_data[i][j+1];
} else {
d[j] = null;
}
}
grid.invalidateRow(i);
}
}
grid.updateRowCount();
grid.render();
}
jQuery(document).on('click', "#gridContextMenu", function(e) {
if (!jQuery(e.target).is("li")) {
return;
}
if (!grid.getEditorLock().commitCurrentEdit()) {
return;
}
var row_id = jQuery(this).data("row");
var column_id = jQuery(this).data("column");
var selected_action = jQuery(e.target).attr("data");
switch (selected_action) {
case "add_row_above": gridAddRow(row_id, "above"); break;
case "add_row_below": gridAddRow(row_id, "below"); break;
case "add_column_before": gridAddColumn(column_id, "before"); break;
case "add_column_after": gridAddColumn(column_id, "after"); break;
case "remove_row": gridRemoveRow(row_id); break;
case "remove_column": gridRemoveColumn(column_id); break;
}
});