⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zpgrid-core.js

📁 zapatec suite 最新版 20070204,非常棒的ajax widgets 工具包
💻 JS
📖 第 1 页 / 共 5 页
字号:
/** * Performs some actions when grid is refreshed. * @private */Zapatec.Grid.prototype.onRefresh = function() {	// Several refresh processes may run simultaneously.	if (this.refreshState > 1) {		this.refreshState--;		return;	}	// If we are responsible for visualisation	if (this.visualizeRefresh && this.visualize) {		this.visualizeRefresh();	}	// Indicates number of running refresh processes	this.refreshState--;	// Onrefresh callback (deprecated)	if (typeof this.config.callbackOnRefresh == 'function') {		this.config.callbackOnRefresh(this);	}	// Fire event	this.fireEvent('gridRefreshed');};/** * Loads data from the JSON source. * * @private * @param {object} oData Input data object */Zapatec.Grid.prototype.loadDataJson = function(oData) {	// Remove index	this.rowsIndex = null;	// Get data	if (!(oData instanceof Object)) {		oData = {};	}	if (!(oData.fields instanceof Array)) {		oData.fields = [];	}	if (!(oData.rows instanceof Array)) {		oData.rows = [];	}	this.data = oData;	// References	this.fields = oData.fields;	this.rows = oData.rows;	// Check and correct input data	if (!this.config.dataPrepared) {		this.prepareData();	}	// Duplicate rows array	this.rowsIndex = this.rows.slice();	// Build primary key	this.primaryKeyColumn = oData.primaryKey;	this.buildPrimaryKey();	// Set page	if (typeof oData.currentPage != 'undefined') {		this.setCurrentPage(oData.currentPage);	} else {		this.setCurrentPage(0);	}	// Show grid	this.show();};/** * Builds primary key. * @private */Zapatec.Grid.prototype.buildPrimaryKey = function() {	var iKey = this.primaryKeyColumn;	if (!this.fields[iKey]) {		this.primaryKey = null;		return;	}	this.primaryKey = {};	var oKey = this.primaryKey;	var aRows = this.rows;	var iRows = aRows.length;	var iRow, sKey;	for (iRow = 0; iRow < iRows; iRow++) {		sKey = this.getCellValueCompare(this.getCellByRow(aRows[iRow], iKey));		if ((typeof sKey == 'string' && sKey.length) || typeof sKey == 'number') {			oKey[sKey] = aRows[iRow];		}	}};/** * Rebuilds primary key. * @private */Zapatec.Grid.prototype.rebuildPrimaryKey = function() {	if (this.primaryKey) {		this.buildPrimaryKey();	}};/** * Displays grid after data loading. * @private */Zapatec.Grid.prototype.show = function() {	// Duplicate rows array	this.filteredRows = this.rows.slice();	// Sort if needed	this.sort();	// Display grid	this.refresh();	// Display filter out forms	this.displayFilterOut();	// Fire event	if (!this.initialized) {		this.initialized = true;		this.fireEvent('gridInitialized');	}};/** * Checks if all required properties of input object are defined. Defines missed * properties. * @private */Zapatec.Grid.prototype.prepareData = function() {	// Prepare fields	var aItems = this.fields;	var iItems = aItems.length;	var iItem, oItem;	for (iItem = 0; iItem < iItems; iItem++) {		oItem = aItems[iItem];		if (!(oItem instanceof Object)) {			oItem = {};		}		oItem.i = iItem;		aItems[iItem] = this.prepareField(oItem);	}	// Prepare spans	aItems = this.rows;	this.prepareSpans(aItems);	// Prepare rows	iItems = aItems.length;	for (iItem = 0; iItem < iItems; iItem++) {		oItem = aItems[iItem];		if (!(oItem instanceof Object)) {			oItem = {};		}		oItem.i = iItem;		aItems[iItem] = this.prepareRow(oItem);	}};/** * Checks if all required properties of the field object are defined. Defines * missed properties. * * @private * @param {object} oField Field object * @return Prepared field object * @type {object} */Zapatec.Grid.prototype.prepareField = function(oField) {	return oField;};/** * Checks if all required properties of the row object are defined. Defines * missed properties. * * @private * @param {object} oRow Row object * @return Prepared row object * @type {object} */Zapatec.Grid.prototype.prepareRow = function(oRow) {	if (!oRow.cells || !(oRow.cells instanceof Array)) {		oRow.cells = [];	}	// Prepare cells	var aCells = oRow.cells;	var iColumns = this.fields.length;	var iCol, oCell;	for (iCol = 0; iCol < iColumns; iCol++) {		// Get cell		oCell = aCells[iCol];		if (!(oCell instanceof Object)) {			oCell = {};		}		// Assign column number		oCell.i = iCol;		// In the rowspan the same cell object is shared among several rows		if (!(oCell.rowspan > 0 && typeof oCell.r != 'undefined')) {			// Assign row number			oCell.r = oRow.i;		}		// Convert		aCells[iCol] = this.convertCell(oCell);		// Skip spanned cells		if (oCell.colspan > 1) {			iCol += oCell.colspan - 1;		}	}	return oRow;};/** * Converts cell to corresponding data type. * * @private * @param {object} oCell Cell object * @return Converted cell object * @type object */Zapatec.Grid.prototype.convertCell = function(oCell) {	return this.convertCellByField(this.getFieldByCell(oCell), oCell);};/** * Converts cell to corresponding data type of the field. * * @private * @param {object} oCell Cell object * @return Converted cell object * @type object */Zapatec.Grid.prototype.convertCellByField = function(oField, oCell) {	if (!(oCell instanceof Object)) {		oCell = {};	}	// Convert by type	if (oField && this.getConvertByType) {		var sMethod = this.getConvertByType(oField.dataType);		if (sMethod) {			oCell = this[sMethod](oCell);		}	}	// Custom convert	oCell = this.convertCellCallback(oCell);	return oCell;};/** * Converts cell using callback function. * * @private * @param {object} oCell Cell object * @return Converted cell object * @type object */Zapatec.Grid.prototype.convertCellCallback = function(oCell) {	if (!(oCell instanceof Object)) {		oCell = {};	}	if (typeof this.config.convert == 'function') {		var convertedValue = this.config.convert(this, oCell);		if (typeof convertedValue != 'undefined') {			if (typeof oCell.o == 'undefined') {				oCell.o = oCell.v;			}			oCell.v = oCell.c = convertedValue;		}	}	return oCell;};/** * Validates cell according to its data type. If value is invalid, sets * "invalid" cell property to true. * * @private * @param {object} oCell Cell object * @return True if valid * @type boolean */Zapatec.Grid.prototype.validateCell = function(oCell) {	if (!(oCell instanceof Object)) {		oCell = {};	}	// Validate by type	if (this.getValidateByType) {		var oField = this.getFieldByCell(oCell);		if (oField) {			var sMethod = this.getValidateByType(oField.dataType);			if (sMethod) {				var undef;				// Valid by default				if (oCell.invalid) {					oCell.invalid = undef;				}				// Validate				var bValid = this[sMethod](oCell);				if (!bValid) {					oCell.invalid = true;				}				// Validate row				var oRow = this.getRowByCell(oCell);				if (oRow) {					if (!bValid) {						oRow.invalid = true;					} else {						// Valid by default						if (oRow.invalid) {							oRow.invalid = undef;						}						// Validate						var aCells = this.getRowCells(oRow);						for (var iCell = 0; iCell < aCells.length; iCell++) {							if (aCells[iCell] && aCells[iCell].invalid) {								oRow.invalid = true;								break;							}						}					}				}				return bValid;			}		}	}	// Default is true	return true;};/** * Changes the content of the grid, replacing, adding or removing rows. * * <pre> * Input object format: * * { *   atKey: [string, optional] primary key value at which to start *    changing the grid, *   atRowId: [number, optional] id of row at which to start changing the grid, *   atRow: [number, optional, private] index of row in rows array at which to *    start changing the grid, *   afterKey: [string, optional] primary key value after which to start *    changing the grid, *   afterRowId: [number, optional] id of row after which to start changing *    the grid, *   afterRow: [number, optional, private] index of row in rows array after *    which to start changing the grid, *   howMany: [number, optional] number of rows to replace or remove *    (default is 0), *   rows: [object, optional] array of rows to add: *   [ *     { *       cells: *       [ *         { *           v: [any] cell value to display, *           c: [any, optional] cell value to compare, *           o: [any, optional] original cell value, *           style: [string, optional] table cell style attribute *         }, *         ... *       ], *       style: [string, optional] table row style attribute *     }, *     ... *   ], *   noRefresh: [boolean, optional] indicates that grid should not be refreshed *    after changing (default is false) (useful when several changes go one by *    one) * } *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -