35
Name
Type
Description
For example, the code below creates an ODataCollectionView and specifies that
hat
'Freight' values, which are stored as strings in the database, should be converted
into numbers; and that three date fields should be converted into dates:
var orders = new wijmo.data.ODataCollectionView(url, 'Orders', {
dataTypes: {
Freight: wijmo.DataType.Number
OrderDate: wijmo.DataType.Date,
RequiredDate: wijmo.DataType.Date,
ShippedDate: wijmo.DataType.Date,
}
});
This property is useful when the database contains data stored in formats that do
not conform to common usage.
In most cases you don't have to provide information about the data types, because
the inferDataTypes property handles the conversion of Date values
es
automatically.
If you do provide explicit type information, the inferDataTypes property is not
not
applied. Because of this, any data type information that is provided should be
complete, including all fields of type Date.
fields
string[]
Gets or sets an array containing the names of the fields to retrieve from the data
source.
If this property is set to null or to an empty array, all fields are retrieved.
For example, the code below creates an ODataCollectionView that gets only
nly
three fields from the 'Categories' table in the database:
var categories = new wijmo.data.ODataCollectionView(url, 'Categories', {
fields: ['CategoryID', 'CategoryName', 'Description']
32
Name
Type
Description
});
filter
IPredicate
Gets or sets a callback used to determine if an item is suitable for inclusion in the
view.
The callback function should return true if the item passed in as a parameter
should be included in the view.
NOTE: If the filter function needs a scope (i.e. a meaningful 'this' value)
remember to set the filter using the 'bind' function to specify the 'this' object. For
example:
collectionView.filter = this._filter.bind(this);
(inherited from CollectionView).
.
filterDefinition
string
Gets or sets a string containing an OData filter specification to be used for
filtering the data on the server.
The filter definition syntax is described in the OData documentation.
.
For example, the code below causes the server to return records where the
'CompanyName' field starts with 'A' and ends with 'S':
view.filterDefinition = "startswith(CompanyName, 'A') and endswith(CompanyName, 'B')";
Filter definitions can be generated automatically. For example,
the FlexGridFilter component detects whether its data source is
is
anODataCollectionView and automatically updates both
th
the filter and filterDefiniton properties.
ties.
45
Name
Type
Description
Note that the filterDefinition property is applied even if
if
the filterOnServer property is set to false. This allows you to apply server and
and
client filters to the same collection, which can be useful in a number of scenarios.
For example, the code below uses the filterDefinition property to filter on the
he
server and the filter property to further filter on the client. The collection will
ill
show items with names that start with 'C' and have unit prices greater than 20:
var url = 'http://services.odata.org/V4/Northwind/Northwind.svc/';
var data = new wijmo.odata.ODataCollectionView(url, 'Products', {
oDataVersion: 4,
filterDefinition: 'startswith(ProductName, \'C\')', // server filter
r
filterOnServer: false, // client filter
filter: function(product) {
return product.UnitPrice > 20;
},
});
filterOnServer
boolean
Gets or sets a value that determines whether filtering should be performed on the
server or on the client.
Use the filter property to perform filtering on the client, and use
se
the filterDefinition property to perform filtering on the server.
.
In some cases it may be desirable to apply independent filters on the
client and on the server.
.
You can achieve this by setting (1) the filterOnServer property to false and
nd
the filter property to a filter function (to enable client-side filtering) and (2)
(2)
the filterDefinition property to a filter string (to enable server-side filtering).
.
groupDescriptions
ObservableArray
Gets a collection of GroupDescription objects that describe how the items in the
collection are grouped in the view.
(inherited from CollectionView).
50
Name
Type
Description
groups
CollectionViewGroup[]
Gets an array of CollectionViewGroup objects that represents the top-level
groups.
(inherited from CollectionView).
inferDataTypes
boolean
Gets or sets a value that determines whether fields that contain strings that look
like standard date representations should be converted to dates automatically.
This property is set to true by default, because the ODataCollectionView class
ass
uses JSON and that format does not support Date objects.
This property has no effect if specific type information is provided using
the dataTypes property.
isAddingNew
boolean
Gets a value that indicates whether an add transaction is in progress.
(inherited from CollectionView).
isEditingItem
boolean
Gets a value that indicates whether an edit transaction is in progress.
(inherited from CollectionView).
isEmpty
boolean
Gets a value that indicates whether this view contains no items.
(inherited from CollectionView).
isLoading
boolean
Gets a value that indicates the ODataCollectionView is currently loading data.
.
This property can be used to provide progress indicators.
isPageChanging
boolean
Gets a value that indicates whether the page index is changing.
(inherited from CollectionView).
isUpdating
Gets a value that indicates whether notifications are currently suspended
(see beginUpdate and endUpdate).
(inherited from CollectionView).
itemCount
number
Gets the total number of items in the view taking paging into account.
(inherited from CollectionView).
items
any[]
Gets items in the view.
(inherited from CollectionView).
42
Name
Type
Description
itemsAdded
ObservableArray
Gets an ObservableArray containing the records that were added to the
collection since trackChanges was enabled.
(inherited from CollectionView).
itemsEdited
ObservableArray
Gets an ObservableArray containing the records that were edited in the
collection since trackChanges was enabled.
(inherited from CollectionView).
itemsRemoved
ObservableArray
Gets an ObservableArray containing the records that were removed from the
collection since trackChanges was enabled.
(inherited from CollectionView).
keys
string[]
Gets or sets an array containing the names of the key fields.
Key fields are required for update operations (add/remove/delete).
newItemCreator
Function
Gets or sets a function that creates new items for the collection.
If the creator function is not supplied, the CollectionView will try to create an
an
uninitialized item of the appropriate type.
If the creator function is supplied, it should be a function that takes no parameters
and returns an initialized object of the proper type for the collection.
(inherited from CollectionView).
.
oDataVersion
number
Gets or sets the OData version used by the server.
There are currently four versions of OData services, 1.0 through 4.0. Version 4.0
is used by the latest services, but there are many legacy services still in operation.
If you know what version of OData your service implements, set
the oDataVersion property to the appropriate value (1 through 4) when creating
ng
the ODataCollectionView (see example below).
).
43
Name
Type
Description
var url = 'http://services.odata.org/Northwind/Northwind.svc';
var categories = new wijmo.odata.ODataCollectionView(url, 'Categories', {
oDataVersion: 1.0, // legacy OData source
fields: ['CategoryID', 'CategoryName', 'Description'],
sortOnServer: false
});
If you do not know what version of OData your service implements (perhaps you
are writing an OData explorer application), then do not specify the version. In
this case, the ODataCollectionView will get this information from the server.
er.
This operation requires an extra request, but only once per service URL, so the
overhead is small.
pageCount
number
Gets the total number of pages.
pageIndex
number
Gets the zero-based index of the current page.
(inherited from CollectionView).
pageOnServer
boolean
Gets or sets a value that determines whether paging should be performed on the
server or on the client.
Use the pageSize property to enable paging.
pageSize
number
Gets or sets the number of items to display on a page.
requestHeaders
any
Gets or sets an object containing request headers to be used when sending or
requesting data.
The most typical use for this property is in scenarios where authentication is
required. For example:
var categories = new wijmo.odata.ODataCollectionView(serviceUrl, 'Categories', {
fields: ['Category_ID', 'Category_Name'],
requestHeaders: { Authorization: db.token }
});
sortConverter
Function
Gets or sets a function used to convert values when sorting.
44
Name
Type
Description
If provided, the function should take as parameters a SortDescription, a data
ta
item, and a value to convert, and should return the converted value.
This property provides a way to customize sorting. For example,
the FlexGrid control uses it to sort mapped columns by display value instead of
of
by raw value.
For example, the code below causes a CollectionView to sort the 'country'
ry'
property, which contains country code integers, using the corresponding country
names:
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(',');
collectionView.sortConverter = function (sd, item, value) {
if (sd.property == 'countryMapped') {
value = countries[value]; // convert country id into name
}
return value;
}
(inherited from CollectionView).
.
sortDescriptions
ObservableArray
Gets a collection of SortDescription objects that describe how the items in the
collection are sorted in the view.
(inherited from CollectionView).
sortOnServer
boolean
Gets or sets a value that determines whether sort operations should be performed
on the server or on the client.
Use the sortDescriptions property to specify how the data should be sorted.
.
sourceCollection
any
Gets or sets the underlying (unfiltered and unsorted) collection.
(inherited from CollectionView).
tableName
string
Gets the name of the table (entity) that this collection is bound to.
totalItemCount
number
Gets the total number of items in the view before paging is applied.
39
Name
Type
Description
trackChanges
boolean
Gets or sets a value that determines whether the control should track changes to
the data.
If trackChanges is set to true, the CollectionView keeps track of changes to the
to the
data and exposes them through the itemsAdded ,itemsRemoved ,
,
and itemsEdited collections.
.
Tracking changes is useful in situations where you need to update the server after
the user has confirmed that the modifications are valid.
After committing or cancelling changes, use the clearChanges method to clear
ar
the itemsAdded , itemsRemoved , and itemsEdited collections.
ions.
The CollectionView only tracks changes made when the
he
proper CollectionView methods are used
ed
(editItem /commitEdit,addNew/commitNew, and remove). Changes made
anges made
directly to the data are not tracked.
(inherited from CollectionView).
.
useStableSort
boolean
Gets or sets whether to use a stable sort algorithm.
Stable sorting algorithms maintain the relative order of records with equal keys.
For example, consider a collection of objects with an "Amount" field. If you sort
the collection by "Amount", a stable sort will keep the original order of records
with the same Amount value.
This property is false by default, which causes the CollectionView to use
use
JavaScript's built-in sort method, which is very fast but not stable.
.
38
Name
Type
Description
Setting stableSort to true increases sort times by 30% to 50%, which can be
be
significant for large collections.
(inherited from CollectionView).
.
Methods
Name
Parameters
Description
addNew(): any
Creates a new item and adds it to the
collection.
This method takes no parameters. It
creates a new item, adds it to the
collection, and prevents refresh
operations until the new item is
committed using
the commitNew method or canceled
ed
using the cancelNew method.
.
The code below shows how
the addNew method is typically used:
:
// create the new item, add it to the
collection
var newItem = view.addNew();
// initialize the new item
newItem.id = getFreshId();
newItem.name = 'New Customer';
// commit the new item so the view can be
refreshed
view.commitNew();
You can also add new items by
pushing them into
38
Name
Parameters
Description
the sourceCollection and then calling
ing
therefresh method. The main
n
advantage of addNew is in user-
r-
interactive scenarios (like adding new
items in a data grid), because it gives
users the ability to cancel the add
operation. It also prevents the new
item from being sorted or filtered out
of view until the add operation is
committed.
Returns The item that was added to
the collection.
(inherited from CollectionView).
.
beginUpdate()
Suspend refreshes until the next call
to endUpdate.
(inherited from CollectionView).
cancelEdit()
Ends the current edit transaction and,
if possible, restores the original value
to the item.
(inherited from CollectionView).
cancelNew()
Ends the current add transaction and
discards the pending new item.
(inherited from CollectionView).
clearChanges()
Clears all changes by removing all
items in
the itemsAdded , itemsRemoved ,
and itemsEdited collections.
Documents you may be interested
Documents you may be interested