DevExtreme Vue - DataSource Methods
This section describes methods that control the DataSource.
cancel(operationId)
Cancels the load operation with a specific identifier.
An operation identifier.
true if the operation was canceled; false if it was not found.
dispose()
Disposes of all the resources allocated to the DataSource instance.
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // DataSource is configured here
- });
- export default {
- data() {
- return {
- ds
- }
- },
- beforeDestroy() {
- ds.dispose();
- },
- // ...
- }
- </script>
filter()
Gets the filter property's value.
A filter expression.
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // ...
- filter: ['age', '>', 18]
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- this.filterExpr = ds.filter(); // returns ["age", ">", 18]
- },
- // ...
- }
- </script>
See Also
filter(filterExpr)
Sets the filter property's value.
A filter expression.
Pass null to clear filtering settings.
Call the load() method to update the UI component bound to the DataSource:
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // DataSource is configured here
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- ds.filter(['age', '>', 18]);
- // or
- // ds.filter('age', '>', 18);
- ds.load();
- },
- // ...
- }
- </script>
See Also
group()
Gets the group property's value.
A group expression.
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // ...
- group: { selector: 'employeeID', desc: true }
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- this.groupExpr = ds.group(); // returns { selector: "employeeID", desc: true }
- },
- // ...
- }
- </script>
See Also
group(groupExpr)
Sets the group property's value.
A group expression.
Call the load() method to update the UI component bound to the DataSource:
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // DataSource is configured here
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- ds.group({ selector: 'employeeID', desc: true });
- ds.load();
- },
- // ...
- }
- </script>
See Also
isLastPage()
Checks whether the count of items on the current page is less than the pageSize. Takes effect only with enabled paging.
true if the item count is less than the pageSize; otherwise false.
isLoaded()
Checks whether data is loaded in the DataSource.
true if data is loaded; otherwise false.
isLoading()
Checks whether data is being loaded in the DataSource.
true if data is being loaded; otherwise false.
items()
Gets an array of data items on the current page.
Array<any>
Data items.
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // DataSource is configured here
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- this.dataItems = ds.items();
- },
- // ...
- }
- </script>
key()
Gets the value of the underlying store's key property.
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- store: {
- // ...
- key: 'ProductID'
- }
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- this.keyProps = ds.key(); // returns "ProductID"
- },
- // ...
- }
- </script>
See Also
- key in ArrayStore | CustomStore | LocalStore | ODataStore
load()
Starts loading data.
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // DataSource is configured here
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- ds.load()
- .then(
- (data) => { /* Process "data" here */ },
- (error) => { /* Handle the "error" here */ }
- )
- },
- // ...
- }
- </script>
The Promise returned from this method is extended with the operationId field which you can use to cancel the invoked operation. See cancel(operationId) for details.
See Also
loadOptions()
Gets an object with current data processing settings.
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // DataSource is configured here
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- this.loadOptions = ds.loadOptions();
- },
- // ...
- }
- </script>
off(eventName)
Detaches all event handlers from a single event.
The event's name.
The object for which this method is called.
See Also
off(eventName, eventHandler)
Detaches a particular event handler from a single event.
The object for which this method is called.
See Also
on(eventName, eventHandler)
Subscribes to an event.
The object for which this method is called.
Use this method to subscribe to one of the events listed in the Events section.
See Also
on(events)
Subscribes to events.
Events with their handlers: { "eventName1": handler1, "eventName2": handler2, ...}
The object for which this method is called.
Use this method to subscribe to several events with one method call. Available events are listed in the Events section.
See Also
pageIndex(newIndex)
Sets the index of the page that should be loaded on the next load() method call.
A zero-based page index.
Call the load() method to update the UI component bound to the DataSource:
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // ...
- paginate: true,
- pageSize: 10
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- ds.pageIndex(2);
- ds.load();
- },
- // ...
- }
- </script>
pageSize(value)
Sets the page size.
A new page size value.
Call the load() method to update the UI component bound to the DataSource:
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // ...
- paginate: true,
- pageSize: 10
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- ds.pageSize(15);
- ds.load();
- },
- // ...
- }
- </script>
paginate(value)
Sets the paginate property's value.
A new value.
Call the load() method to update the UI component bound to the DataSource:
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // ...
- paginate: true,
- pageSize: 10
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- ds.paginate(false);
- ds.load();
- },
- // ...
- }
- </script>
reload()
Clears currently loaded DataSource items and calls the load() method.
DataSource reloads data starting from the current page index. To reload all data, set pageIndex to 0 before you call reload().
The Promise returned from this method is extended with the operationId field which you can use to cancel the invoked operation. See cancel(operationId) for details.
requireTotalCount()
Gets the requireTotalCount property's value.
The property's value.
requireTotalCount(value)
Sets the requireTotalCount property's value.
A new value.
Call the load() method to update the UI component bound to the DataSource:
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // ...
- requireTotalCount: true
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- ds.requireTotalCount(false);
- ds.load();
- },
- // ...
- }
- </script>
searchExpr()
Gets the searchExpr property's value.
The property's value; described in the Getters and Setters section.
searchExpr(expr)
Sets the searchExpr property's value.
A new value; described in the Getters and Setters section.
searchOperation(op)
Sets the searchOperation property's value.
A new value. Can be one of the following: "=", "<>", ">", ">=", "<", "<=", "startswith", "endswith", "contains" and "notcontains".
searchValue(value)
Sets the searchValue property's value.
A new value.
Call the load() method to update the UI component bound to the DataSource:
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // DataSource is configured here
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- ds.searchExpr('firstName');
- ds.searchOperation('contains');
- ds.searchValue('Jo');
- ds.load();
- },
- // ...
- }
- </script>
See Also
select(expr)
Sets the select property's value.
A select expression.
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // DataSource is configured here
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- ds.select(['firstName', 'lastName', 'birthDate']);
- // or
- // ds.select('firstName', 'lastName', 'birthDate');
- },
- // ...
- }
- </script>
See Also
sort(sortExpr)
Sets the sort property's value.
A sort expression.
Call the load() method to update the UI component bound to the DataSource:
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // DataSource is configured here
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- ds.sort({ selector: 'Discount', desc: true });
- ds.load();
- },
- // ...
- }
- </script>
See Also
store()
Gets the instance of the store underlying the DataSource.
A store instance.
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- store: {
- // Store is configured here
- }
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- this.store = ds.store();
- },
- // ...
- }
- </script>
totalCount()
Gets the number of data items in the store after the last load() operation without paging. Takes effect only if requireTotalCount is true
The number of data items.
- <script>
- import DataSource from 'devextreme/data/data_source';
- const ds = new DataSource({
- // ...
- requireTotalCount: true
- });
- export default {
- data() {
- return {
- ds
- }
- },
- mounted() {
- this.itemCount = ds.totalCount();
- },
- // ...
- }
- </script>