📄 databoundcomponent.js
字号:
// that matches the provided criteria, and displays the matching data in this component.// <P>// If there are a large number of matching records, paging will automatically be enabled, so// that initially a smaller number of records will be retrieved and further records will// be fetched as the user navigates the dataset.// <P>// When first called, this method will create a +link{class:ResultSet}, which will be// configured based on component settings such as +link{attr:dataBoundComponent.fetchOperation}// and +link{attr:dataBoundComponent.dataPageSize}, as well as the general purpose// +link{listGrid.dataProperties}. The ResultSet is then available as// <code>component.data</code>.// <P>// Subsequent calls to fetchData() will simply call +link{resultSet.setCriteria,setCriteria()}// on the created ResultSet with the passed criteria.<br>// In some cases fetchData() will not need to context the server as the new criteria can be// satisfied by performing a client-side filter against the currently cached set of data.// You can determine whether criteria will cause a fetch by calling // +link{ResultSet.willFetchData()}.<br>// If you need to force a server fetch, you can call +link{resultSet.invalidateCache()} via// <code>component.data.invalidateCache()</code> to do so. // If for any reason you need to rebuild the ResultSet, you can call// <P>// This method takes an optional callback parameter (set to a +link{DSCallback}) to fire when// the fetch completes. Note that this callback will not fire if no server fetch is performed.// In this case the data is updated synchronously, so as soon as this method completes you// can interact with the new data. If necessary we recomment using // +link{ResultSet.willFetchData()} before calling this method to determine whether or not// a server fetch will occur.<br>// In addition to the callback parameter for this method, developers can use // +link{ResultSet.dataArrived()} to be notified every time ResultSet data is loaded.//// @param [criteria] (Criteria) Search criteria. // If a +link{DynamicForm} is passed in as this argument// instead of a raw criteria object, will be derived by calling// +link{DynamicForm.getValuesAsCriteria()}// @param [callback] (DSCallback) callback to invoke on completion// @param [requestProperties] (DSRequest) additional properties to set on the DSRequest// that will be issued//// @group dataBoundComponentMethods// @visibility internal//<fetchData : function (criteria, callback, requestProperties) { this._filter("fetch", criteria, callback, requestProperties);},//> @attr dataBoundComponent.autoFetchData (boolean : false : IR)// If true, when this component is first drawn, automatically call <code>this.fetchData()</code>//// @group dataBoundComponentMethods// @visibility internal// @see fetchData()//<//> @attr dataBoundComponent.initialCriteria (Criteria : null :IR)// Criteria to be used when +link{autoFetchData} is set.// @visibility internal//<//> @method dataBoundComponent.fetchRelatedData()// Based on the relationship between the DataSource this component is bound to and the// DataSource specified as the "schema" argument, call fetchData() to retrieve records in this// grid that are related to the passed-in record.// <P>// Relationships between DataSources are declared via +link{dataSourceField.foreignKey}.// <P>// For example, given a DataSource "orders" and another DataSource "orderItems", where// "orderItems" declared a field "orderId" pointing to the primary key field of the "orders"// DataSource", there is a set of records from the "orderItems" DataSource related to any given// record from the "order" DataSource. If this component were bound to "orderItems" and a// record from the "orders"//// @param record (ListGridRecord) DataSource record// @param schema (Canvas or DataSource or ID) schema of the DataSource record, or// DataBoundComponent already bound to that schema// @param [callback] (DSCallback) callback to invoke on completion// @param [requestProperties] (DSRequest) additional properties to set on the DSRequest// that will be issued//// @visibility internal//<fetchRelatedData : function (record, schema, callback, requestProperties) { var otherDS = isc.isA.DataSource(schema) ? schema : isc.isA.String(schema) ? isc.DS.get(schema) : isc.isA.Canvas(schema) ? schema.dataSource : null; if (!otherDS) { this.logWarn("schema not understood: " + this.echoLeaf(schema)); return; } var relationship = this.getDataSource().getTreeRelationship(otherDS); // form criteria to find related records var criteria = {}; criteria[relationship.parentIdField] = record[relationship.idField]; this.fetchData(criteria, callback, requestProperties);},//> @method dataBoundComponent.clearCriteria()// Clear the current criteria used to filter data.//// @param [callback] (DSCallback) callback to invoke on completion// @param [requestProperties] (DSRequest) additional properties to set on the DSRequest// that will be issued//// @see listGrid.fetchData()//// @group dataBoundComponentMethods// @visibility internal//<clearCriteria : function (callback, requestProperties) { this._filter("filter", null, callback, requestProperties);},_filter : function (type, criteria, callback, requestProperties) { if (isc._traceMarkers) arguments.__this = this; //>!BackCompat 2005.3.21 old signature: criteria, context if (requestProperties == null && isc.isAn.Object(callback) && callback.methodName == null) { // old style call, second param (callback) is really requestParams requestProperties = callback; callback = null; } //<!BackCompat requestProperties = this.buildRequest(requestProperties, type, callback); // handle being passed a criteria object (map of keys to values), or a filter-component if (criteria == null) { criteria = {}; } else if (isc.isA.Class(criteria)) { // otherwise assume "filter" is something we can ask for filter criteria // (DynamicForm or ValuesManager) criteria = isc.DynamicForm.getFilterCriteria(criteria); } this.filterWithCriteria(criteria, requestProperties.operation, requestProperties);},filterWithCriteria : function (criteria, operation, context) { context.prompt = (context.prompt || isc.RPCManager.fetchDataPrompt); // get rid of empty criteria that come from raw form values var filterCriteria = isc.DataSource.filterCriteriaForFormValues(criteria); // if not already viewing a result set for this operation, create one for it var resultSet = this.getData(); if (!isc.isA.ResultSet(resultSet) || resultSet.getOperationId("fetch") != operation.ID) { //>DEBUG this.logInfo("Creating new isc.ResultSet for operation '" + operation.ID + "' with filterValues: " + isc.Comm.serialize(filterCriteria)); //<DEBUG var dataSource = this.getDataSource(), resultSet = this.dataProperties || {}; if (this.dataFetchDelay) resultSet.fetchDelay = this.dataFetchDelay; isc.addProperties(resultSet, { operation:operation, filter:filterCriteria, context:context}); resultSet = dataSource.getResultSet(resultSet); } else { // tell the ResultSet the filter changed //>DEBUG this.logDebug("Setting filter to: " + isc.Comm.serialize(filterCriteria)); //<DEBUG // update the context - this allows requestProperties like "showPrompt" / textMatchStyle // to change resultSet.setContext(context); resultSet.setCriteria(filterCriteria); } // we will ask the result set for the data we currently need to display, // which will cause data to be fetched this.setData(resultSet); if (!context._suppressFetch && this.requestVisibleRows != null) { var data = this.data, fetchDelay = data.fetchDelay; data.fetchDelay = 0; this.requestVisibleRows(); data.fetchDelay = fetchDelay; }},// add this here so that all dataBoundComponents have data available by default.requestVisibleRows : function () { return this.data.get(0);},// Persistence// -----------------------------------------------------------------------------//> @method dataBoundComponent.addData()// Perform a DataSource "add" operation to add new records to this component's DataSource.//// @param newRecord (Object) new record// @param [callback] (DSCallback) method to call on operation completion// @param [requestProperties] (DSRequest) additional properties to set on the DSRequest// that will be issued//// @group dataBoundComponentMethods// @visibility internal//<addData : function (newRecord, callback, requestProperties) { return this._performDSOperation("add", newRecord, callback, requestProperties);},//> @method dataBoundComponent.updateData()// Perform a DataSource "update" operation to update existing records in this component's// DataSource.//// @param updatedRecord (Object) updated record// @param [callback] (DSCallback) method to call on operation completion// @param [requestProperties] (DSRequest) additional properties to set on the DSRequest// that will be issued//// @group dataBoundComponentMethods// @visibility internal//<updateData : function (updatedRecord, callback, requestProperties) { return this._performDSOperation("update", updatedRecord, callback, requestProperties);},//> @method dataBoundComponent.removeData()// Perform a DataSource "remove" operation to remove records from this component's// DataSource.//// @param data (Object) primary key values of record to delete, // (or complete record)// @param [callback] (DSCallback) method to call on operation completion// @param [requestProperties] (DSRequest) additional properties to set on the DSRequest// that will be issued//// @group dataBoundComponentMethods// @visibility internal//<removeData : function (recordKeys, callback, requestProperties) { return this._performDSOperation("remove", recordKeys, callback, requestProperties);},_performDSOperation : function (operationType, data, callback, requestProperties) { if (isc._traceMarkers) arguments.__this = this; //>!BackCompat 2005.3.21 old signature: data, context if (requestProperties == null && isc.isAn.Object(callback) && callback.methodName == null) { // old style call, second param (callback) is really requestParams requestProperties = callback; callback = null; } //<!BackCompat if (this.saveLocally) { if (operationType == "update") { // look up record by PK var record = this.data.get(this.getDataSource().findByKeys(data, this.data)); //this.logWarn("record is: " + this.echo(record) + ", data is: " + this.echo(data)); // update it isc.addProperties(record, data); // manaully fire dataChanged return this.data.dataChanged(); } else if (operationType == "add") { // dataChanged fires automatically this.data.add(data); return; } } return this.getDataSource().performDSOperation(operationType, data, callback, requestProperties);},//> @method dataBoundComponent.removeSelectedData()// Remove the currently selected records from this component.// If this is a databound grid, the records will be removed directly from the DataSource.// <P>// If no records are selected, no action is taken. The grid will automatically be// updated if the record deletion succeeds.//// @param [callback] (callback) callback to fire when the data has been removed// @param [requestProperties] (DSRequest) additional properties to set on the DSRequest// that will be issued//// @group dataBoundComponentMethods// @visibility internal//<removeSelectedData : function (callback, requestProperties) { // if this is not a databound grid, remove the data from the local data array instead if (this.dataSource == null) { if (this.data) { this.data.removeList(this.getSelection()); if (callback) this.fireCallback(callback); } return; } //>!BackCompat 2005.3.21 old signature: criteria, context if (requestProperties == null && isc.isAn.Object(callback) && callback.methodName == null) { // old style call, first param (callback) is really requestParams requestProperties = callback; callback = null; } //<!BackCompat if (this.saveLocally) return this.data.removeList(this.getSelection()); var context = this.buildRequest(requestProperties, "remove", callback), selection = this.selection.getSelection(), dataSource = this.getDataSource(); if (selection.length > 0) this.deleteRecords(selection, context.operation, context, dataSource); // notify that they have to select something to delete first... ???},// delete a specific list of records from the serverdeleteRecords : function (records, deleteOperation, context, dataSource) { isc.addProperties(context, { prompt:(context.prompt || isc.RPCManager.removeDataPrompt) }); // perform the delete as a multi-op, one per record var wasAlreadyQueuing = isc.RPCManager.startQueue(); if (!isc.isAn.Array(records)) records = [records]; for (var i = 0; i < records.length; i++) { dataSource.performDSOperation(deleteOperation.type, records[i], null, context); } // don't kickoff the transaction unless this flow initiated queuing, in case caller // wants to include other operations if (!wasAlreadyQueuing) isc.RPCManager.sendQueue();},//> @method dataBoundComponent.getSelection()// Returns all selected records, as an Array.//// @return (Array of ListGridRecord) list of records, empty list if nothing selected// @group selection// @visibility internal// @example databoundRemove//<getSelection : function () { if (!this.selection) return null; if (this.canSelectCells) { var selectedCells = this.selection.getSelectedCells(); if (selectedCells == null) return null; var cellRecords = []; for (var i = 0; i < selectedCells.length; i++) { var selectedCell = selectedCells[i], cellRecord = this.getCellRecord(selectedCell[0], selectedCell[1]) ; if (cellRecord == null) continue; // record for this cell cellRecords.add(cellRecord); } return cellRecords; } else { return this.selection.getSelection(); }},//> @method dataBoundComponent.getSelectedRecord()// Return the first selected record in this component// @group selection// @return (ListGridRecord) first selected record, or null if nothing selected// @visibility internal// @example databoundRemove//<getSelectedRecord : function() { if (!this.selection) return null; return this.selection.getSelectedRecord();}});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -