What is @syncfusion/ej2-data?
@syncfusion/ej2-data is a data management package that provides a set of utilities for handling data operations such as sorting, filtering, grouping, and querying. It is part of the Syncfusion Essential JS 2 suite and is designed to work seamlessly with other Syncfusion components.
What are @syncfusion/ej2-data's main functionalities?
DataManager
The DataManager feature allows you to manage and manipulate data collections. In this example, a DataManager instance is created with a sample data array, and a query is executed to filter out records where the age is greater than 28.
const { DataManager, Query } = require('@syncfusion/ej2-data');
const data = [
{ id: 1, name: 'John', age: 30 },
{ id: 2, name: 'Jane', age: 25 },
{ id: 3, name: 'Doe', age: 35 }
];
const dataManager = new DataManager(data);
const query = new Query().where('age', 'greaterThan', 28);
const result = dataManager.executeLocal(query);
console.log(result);
Sorting
The Sorting feature allows you to sort data collections based on specified fields. In this example, the data is sorted by the 'name' field in ascending order.
const { DataManager, Query } = require('@syncfusion/ej2-data');
const data = [
{ id: 1, name: 'John', age: 30 },
{ id: 2, name: 'Jane', age: 25 },
{ id: 3, name: 'Doe', age: 35 }
];
const dataManager = new DataManager(data);
const query = new Query().sortBy('name', 'ascending');
const result = dataManager.executeLocal(query);
console.log(result);
Grouping
The Grouping feature allows you to group data collections based on specified fields. In this example, the data is grouped by the 'group' field.
const { DataManager, Query } = require('@syncfusion/ej2-data');
const data = [
{ id: 1, name: 'John', age: 30, group: 'A' },
{ id: 2, name: 'Jane', age: 25, group: 'B' },
{ id: 3, name: 'Doe', age: 35, group: 'A' }
];
const dataManager = new DataManager(data);
const query = new Query().group('group');
const result = dataManager.executeLocal(query);
console.log(result);
Aggregates
The Aggregates feature allows you to perform aggregate operations like sum, average, min, and max on data collections. In this example, the sum of the 'age' field is calculated.
const { DataManager, Query, DataUtil } = require('@syncfusion/ej2-data');
const data = [
{ id: 1, name: 'John', age: 30 },
{ id: 2, name: 'Jane', age: 25 },
{ id: 3, name: 'Doe', age: 35 }
];
const dataManager = new DataManager(data);
const query = new Query().select(['age']);
const result = dataManager.executeLocal(query);
const totalAge = DataUtil.aggregates.sum(result, 'age');
console.log(totalAge);
Other packages similar to @syncfusion/ej2-data
lodash
Lodash is a popular utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. It offers similar functionalities to @syncfusion/ej2-data, such as sorting, filtering, and aggregating data. However, Lodash is more general-purpose and not specifically designed for integration with UI components.
underscore
Underscore is another utility library that provides functional programming helpers for working with arrays, objects, and other data types. Like Lodash, it offers functionalities similar to @syncfusion/ej2-data, including sorting, filtering, and grouping. Underscore is known for its simplicity and ease of use.
rxdb
RxDB is a real-time NoSQL database for JavaScript applications. It provides data management capabilities, including querying, sorting, and filtering, similar to @syncfusion/ej2-data. RxDB is designed for offline-first applications and supports real-time data synchronization.
Overview
@syncfusion/ej2-data
is a data management package to perform data operations such as grouping, sorting in client applications.
It will act as an abstraction for using local data sources like array of JavaScript objects
and remote data sources like web services returning JSON, JSONP, oData or XML.
Changelog
Check the changelog here