📄 zpgrid-core.js
字号:
* <b>gridPrepareModify</b> before splice or query is started. * * <b>gridModified</b> when splice or query is completed. * * <b>gridPrepareFilter</b> before filtering is started. * * <b>gridFiltered</b> when filtering is completed. * * <b>gridResizedColumn</b> when standard output is used and column was resized * manually. Listener receives two arguments: column id and width increment in * pixels. Width increment can be negative. * * <b>gridMovedColumn</b> when column is moved. Listener receives following * argument: * { * fieldId: [number] zero-based id of the moved field, * position: [number] new zero-based column position * } * * <b>gridCellMousedown</b> when mouse down event occurs on the cell's td * element. Listener receives two arguments: row id and cell id. * </pre> * * @constructor * @extends Zapatec.Widget * @param {object} oArg User configuration */Zapatec.Grid = function(oArg) { // Call constructor of superclass Zapatec.Grid.SUPERconstructor.call(this, oArg);};/** * Unique static id of the widget class. Gives ability for Zapatec#inherit to * determine and store path to this file correctly when it is included using * Zapatec#include. When this file is included using Zapatec#include or path * to this file is gotten using Zapatec#getPath, this value must be specified * as script id. * @private */Zapatec.Grid.id = 'Zapatec.Grid';// Inherit WidgetZapatec.inherit(Zapatec.Grid, Zapatec.Widget);/** * Initializes grid. * * @param {object} oArg User configuration */Zapatec.Grid.prototype.init = function(oArg) { // Indicates that initialization process is completed this.initialized = false; // Call parent method Zapatec.Grid.SUPERclass.init.call(this, oArg); var oConfig = this.config; // Holds grid data this.data = {}; // Reference to fields array in data object this.fields = []; // Reference to rows array in data object this.rows = []; // Array where indexes are the same as row ids to reference grid rows by id this.rowsIndex = []; // Holds filtered row objects this.filteredRows = []; // Holds current page number this.currentPage = 0; // Holds current frame for autoresize this.autoresizeFrame = { direction: 0, currentRow: 0, visibleRows: oConfig.rowsPerPage }; // Holds current vertical offset on the page this.currentVerticalOffset = 0; // Holds current horizontal offset on the page this.currentHorizontalOffset = 0; // Holds sorting order this.order = []; // Initially may be sorted on the specified column and in the specified order // null is object if (typeof oConfig.sortColumn != 'object') { this.order.push({ col: oConfig.sortColumn * 1, desc: oConfig.sortDesc, lt: oConfig.sortDesc ? 1 : -1, gt: oConfig.sortDesc ? -1 : 1 }); } // Object that holds last selection to be able to modify it this.lastSelection = null; // Load data from the specified source this.loadData();};/** * Reconfigures the grid with new config options after it was initialized. * May be used to change look or behavior of the grid after it has loaded * the data. In the argument pass only values for changed config options. * There is no need to pass config options that were not changed. * * <pre> * Note: "sortColumn" and "sortDesc" config options are ignored by this method * because they are useful only on initialization. To sort the grid after it was * initialized use sort method instead. * </pre> * * @param {object} oArg Changes to user configuration */Zapatec.Grid.prototype.reconfigure = function(oArg) { // Call parent method Zapatec.Grid.SUPERclass.reconfigure.call(this, oArg); // Redraw grid this.refresh();};/** * Configures grid. Gets called from parent init method. * * @private * @param {object} oArg User configuration */Zapatec.Grid.prototype.configure = function(oArg) { // Define config options this.defineConfigOption('show_asis', false); this.defineConfigOption('funcStyle'); this.defineConfigOption('convert'); this.defineConfigOption('container'); this.defineConfigOption('headerContainer'); this.defineConfigOption('totalsContainer'); this.defineConfigOption('visibleRows', 0); this.defineConfigOption('visibleColumns', 0); this.defineConfigOption('rowsPerPage', 0); this.defineConfigOption('paginationContainer'); this.defineConfigOption('border'); this.defineConfigOption('fitIntoParent'); this.defineConfigOption('horizontal', false); this.defineConfigOption('selectRows', true); this.defineConfigOption('selectCells', true); this.defineConfigOption('activeRows', true); this.defineConfigOption('activeCells', true); this.defineConfigOption('multipleSelect', true); this.defineConfigOption('callbackHeaderDisplay'); this.defineConfigOption('callbackDataDisplay'); this.defineConfigOption('callbackRowDisplay'); this.defineConfigOption('callbackTotalsDisplay'); this.defineConfigOption('callbackTotalDisplay'); this.defineConfigOption('callbackPaginationDisplay'); this.defineConfigOption('callbackRowOnClick'); this.defineConfigOption('callbackRowOnRightClick'); this.defineConfigOption('callbackCellOnClick'); this.defineConfigOption('callbackCellOnRightClick'); this.defineConfigOption('callbackRowOnDblClick'); this.defineConfigOption('callbackCellOnDblClick'); this.defineConfigOption('callbackRowSelect'); this.defineConfigOption('callbackCellSelect'); this.defineConfigOption('callbackRowUnselect'); this.defineConfigOption('callbackCellUnselect'); this.defineConfigOption('callbackOnRefresh'); this.defineConfigOption('sortColumn'); this.defineConfigOption('sortDesc'); this.defineConfigOption('filterOut', []); this.defineConfigOption('totals', []); this.defineConfigOption('dataPrepared', false); this.defineConfigOption('dataOnDemand', false); this.defineConfigOption('fixedLeft', 0); this.defineConfigOption('columnWidth', 'auto'); this.defineConfigOption('rowHeight', 'auto'); this.defineConfigOption('mouseSelect', true); this.defineConfigOption('dragAndDropCells', false); this.defineConfigOption('dragAndDropColumns', false); this.defineConfigOption('langId', 'Zapatec.Grid'); this.defineConfigOption('lang', 'eng'); // Call parent method Zapatec.Grid.SUPERclass.configure.call(this, oArg); // Correct config options var fGetElById = Zapatec.Widget.getElementById; var fCorrectCssLength = Zapatec.Utils.correctCssLength; var oConfig = this.config; // Correct rowsPerPage config option oConfig.rowsPerPage = parseInt(oConfig.rowsPerPage); if (isNaN(oConfig.rowsPerPage)) { oConfig.rowsPerPage = 0; } // Correct visibleRows config option oConfig.visibleRows = parseInt(oConfig.visibleRows); if (isNaN(oConfig.visibleRows)) { oConfig.visibleRows = 0; } // Correct visibleColumns config option oConfig.visibleColumns = parseInt(oConfig.visibleColumns); if (isNaN(oConfig.visibleColumns)) { oConfig.visibleColumns = 0; } // There is no sense to use dataOnDemand without rowsPerPage if (!oConfig.rowsPerPage) { oConfig.dataOnDemand = false; } // Indicates that we are responsible for visualisation this.visualize = true; if (typeof oConfig.callbackHeaderDisplay == 'function' && (typeof oConfig.callbackRowDisplay == 'function' || typeof oConfig.callbackDataDisplay == 'function')) { this.visualize = false; // Prevent displaying of "Theme not found" message oConfig.theme = ''; } // Grid container this.container = fGetElById(oConfig.container); // Grid header container this.headerContainer = fGetElById(oConfig.headerContainer); // Grid totals container this.totalsContainer = fGetElById(oConfig.totalsContainer); // Grid pagination containers array this.paginationContainers = []; var vPagCont = oConfig.paginationContainer; if (typeof vPagCont != 'undefined') { if (vPagCont instanceof Array) { var aPagCont = this.paginationContainers; var iEls = vPagCont.length; var iEl, oEl; for (iEl = 0; iEls--; iEl++) { oEl = fGetElById(vPagCont[iEl]); if (oEl) { aPagCont.push(oEl); } } } else { var oEl = fGetElById(vPagCont); if (oEl) { this.paginationContainers.push(oEl); } } } // Grid border element this.border = fGetElById(oConfig.border); if (!this.border && this.container) { // Assume border is parent node of the container this.border = this.container.parentNode; } // Element to fit into this.fitInto = null; if (this.border) { if (typeof oConfig.fitIntoParent == 'boolean') { if (oConfig.fitIntoParent) { this.fitInto = this.border.parentNode; } } else { this.fitInto = fGetElById(oConfig.fitIntoParent); } } // Adjust number of rows per page to fit into specified container if (this.fitInto && typeof this.autoresize == 'function') { this.addEventListener('gridRefreshed', this.autoresize); this.addEventListener('gridResizedColumn', this.autoresize); } // Correct columnWidth config option oConfig.columnWidth = fCorrectCssLength(oConfig.columnWidth); if (oConfig.columnWidth == 'auto' && (this.headerContainer || this.totalsContainer)) { oConfig.columnWidth = '100px'; } // Correct rowHeight config option oConfig.rowHeight = fCorrectCssLength(oConfig.rowHeight); // Setup mouse selection if (oConfig.mouseSelect && this.mouseSelect) { this.addEventListener('gridCellMousedown', this.mouseSelect); } // Setup cell dragging if (oConfig.dragAndDropCells && this.dragCell) { this.addEventListener('gridCellMousedown', this.dragCell); } // Setup column dragging if (oConfig.dragAndDropColumns && this.dragColumn) { this.addEventListener('gridFieldMousedown', this.dragColumn); } // Setup right mouse click callbacks if (typeof oConfig.callbackCellOnRightClick == 'function' || typeof oConfig.callbackRowOnRightClick == 'function') { // Disable context menu window.document.oncontextmenu = function() {return false}; // Add event listener to mouseup event to be able to get button number this.addEventListener('gridCellMouseup', Zapatec.Grid.onCellMouseup); } // Filter out rules this.filterOutRules = oConfig.filterOut; if (!(this.filterOutRules instanceof Array)) { this.filterOutRules = []; } // Totals rules this.totalsRules = oConfig.totals; if (!(this.totalsRules instanceof Array)) { this.totalsRules = []; }};/** * Extends parent method. * @private */Zapatec.Grid.prototype.addStandardEventListeners = function() { // Call parent method Zapatec.Grid.SUPERclass.addStandardEventListeners.call(this); // Add grid specific event listeners this.addEventListener('fetchSourceError', this.displayErrorSource); // If zpgrid-output.js is loaded if (this.displayLoading) { this.addEventListener('fetchSourceStart', this.displayLoading); this.addEventListener('fetchSourceEnd', this.removeLoading); this.addEventListener('loadThemeEnd', this.visualizeThemeLoad); this.addEventListener('loadDataEnd', this.visualizeDataLoad); }};/** * Displays error when external source is malformed. * @private */Zapatec.Grid.prototype.displayErrorSource = function(oError) { alert(this.getMessage('errorSource', this.config.source, oError.errorDescription));};/** * Reloads data from the specified source after grid is initialized. Argument * should be passed only when dataOnDemand config option is true and * callbackSource config option is defined. See description of dataOnDemand * config option for details. * * @param {object} oArg Optional. Argument object */Zapatec.Grid.prototype.loadData = function(oArg) { // Form argument for server side if (this.config.dataOnDemand) { if (typeof oArg != 'object') { oArg = {}; } oArg.currentPage = this.currentPage; if (this.order.length) { oArg.sortColumn = this.order[0].col; oArg.sortDesc = this.order[0].desc; oArg.order = this.order; } oArg.filters = []; for (var iCol = 0; iCol < this.fields.length; iCol++) { var oField = this.fields[iCol]; if (oField) { oArg.filters[iCol] = { hiddenValues: oField.hiddenValues, minValue: oField.minValue, maxValue: oField.maxValue, regexpFilter: oField.regexpFilter, textFilter: oField.textFilter }; } else { oArg.filters[iCol] = {}; } } } // Call parent method Zapatec.Grid.SUPERclass.loadData.call(this, oArg);};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -