Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add DataCollection guides #56

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/data_collection/api/datacollection_add_method.md
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ Either item's id or an array with ids of items.

@example:
// adding a new item into the beginning of a data collection
component.data.add({"value": 57.44787660011765, "id": "u1565340894584"},0);
component.data.add({ "value": 57.44787660011765, "id": "u1565340894584" }, 0);

// adding an array of new items into a data collection
component.data.add([
2 changes: 1 addition & 1 deletion docs/data_collection/api/datacollection_changeid_method.md
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ description: You can explore the changeId method of DataCollection in the docume
@params:
- `id: string | number` - the old id of an item
- `newId: string | number` - optional, the new id; auto-generated if not set
- `silent: boolean` - true, to prevent changing the id; otherwise, false
- `silent: boolean` - optional, *true*, to prevent changing the id; otherwise, *false*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 кажется тут не то описание. silent - если использовать метод с включенным данным флагом, метод будет работать в "тихом" режиме, то есть - без вызова событий. Метод сработает, события будут проигнорированы.


@example:
component.data.changeId("1", "22");
9 changes: 7 additions & 2 deletions docs/data_collection/api/datacollection_filter_method.md
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ description: You can explore the filter method of DataCollection in the document

@short: filters data items in a component

@signature: {'filter(rule?: function | object, config?: object): string;'}
@signature: {'filter(rule?: function | object, config?: object, silent?: boolean): string;'}

@params:
- `rule: function | object` - the filtering criteria
@@ -22,8 +22,13 @@ description: You can explore the filter method of DataCollection in the document
- `item` - a data item the values of which should be compared
- `config: object` - optional, defines the parameters of filtering. It may contain the following properties:
- `id: string` - optional, the id of the filter
- `add: boolean` - optional, defines whether each next filtering will be applied to the already filtered data (<i>true</i>), or to the initial data (<i>false</i>, default)
- `add: boolean` - optional, defines whether each next filtering will be applied to the already filtered data (*true*), or to the initial data (*false*, default)
- `permanent: boolean` - optional, *true* to make the current filter permanent. It will be applied even if the next filtering doesn't have the `add:true` property in its configuration object. Such a filter can be removed just with the [resetFilter()](data_collection/api/datacollection_resetfilter_method.md) method
- `silent: boolean` - optional, if *true*, the update of the DataCollection state won't trigger the component repainting, *false* by default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 откуда тут перерисовка?)) Это частный случай, а может и сработает. Можно в примечаниях написать, что:

после использования данного метода с включенным флагом silent вам потребуется принудительная перерисовка компонента при помощи метода paint()

Флаг silent вызывает метод без вызова событий.


:::info
Note that the use of the `silent` parameter may cause incorrect behavior of the method.
:::

@returns:
- `id: string` - the id of the filter
4 changes: 2 additions & 2 deletions docs/data_collection/api/datacollection_find_method.md
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ description: You can explore the find method of DataCollection in the documentat
- `array` - (optional) an array with items

@returns:
An object of the matching item.
The object of the matching item.

@example:
//searching for an item by the function
@@ -30,7 +30,7 @@ const item = component.data.find(function(item){
});

//searching for an item by the attribute key
const item = component.data.find({by:"text",match:"Manager"});
const item = component.data.find({ by:"text",match:"Manager" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 понимаю, что правка локальная. Если есть возможность, поправ пожалуйста отступы в примерах:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 почти во всех примерах есть такая проблема


@descr:

2 changes: 1 addition & 1 deletion docs/data_collection/api/datacollection_findall_method.md
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ const items = component.data.findAll(function(items){
});

//searching for items by the attribute key
const items = component.data.findAll({by:"text",match:"Manager"});
const items = component.data.findAll({ by:"text",match:"Manager" });

@descr:

Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ description: You can explore the getFilters method of DataCollection in the docu

@params:

- `permanent: boolean` - optional, <i>false</i> by default. Allows getting the list of permanent filters
- `permanent: boolean` - optional, *false* by default. Allows getting the list of permanent filters

@returns:
- `filters: object` - an object with the applied filters, where the key is the id of a filter and the value is an object with the [`rule` and `config` properties](data_collection/api/datacollection_filter_method.md)
2 changes: 1 addition & 1 deletion docs/data_collection/api/datacollection_getitem_method.md
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ const item = component.data.getItem(123);

You can access the original properties of an item like this:

~~~js
~~~jsx
const item = component.data.getItem(123);
const text = item.text;
~~~
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ description: You can explore the getLength method of DataCollection in the docum
The number of elements of a data collection.

@example:
component.data.getLength();
const items = component.data.getLength();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 метод возвращает длину коллекции. Название переменной можно было назвать dataLength

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 по описанию подавлю. В TreeCollection этот метод коварен, и вместо длинны всех данных отобразит длину уровня. Вроде есть об этом запись в TreeCollection. Но я подумал, что в гайдах стоит упомянуть, если не будешь делать отдельный гайд по TreeCollection


@descr:

2 changes: 1 addition & 1 deletion docs/data_collection/api/datacollection_group_method.md
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ group(order: TGroupOrder[], config?: IGroupConfig): void;
- an `IGroupOrder` object that has the following properties:
- `by` - the field name or a function for user-defined grouping
- `map` - (optional) an object for data aggregation in a group, where the keys are field names, and the values can be:
- a tuple `[string, TAggregate]` that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from the `dhx.methods` helper
- a tuple `[string, TAggregate]` that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from the [`dhx.methods`](helpers/data_calculation_functions.md) helper
- a user-defined aggregation function `(i: IDataItem[]) => string | number`
- `summary` - (optional) specifies where the total row is rendered - at the `top` or at the `bottom` of the group
- `config` - (optional) the configuration of data grouping
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@ description: You can explore the isDataLoaded method of DataCollection in the do

# isDataLoaded()

{{pronote This functionality is available in the PRO edition only.}}
:::tip pro version only
The method works with the [Dynamic loading](helpers/lazydataproxy.md) functionality which is available in the PRO edition only.
:::

@short: checks whether the specified data range is loaded from the server

2 changes: 1 addition & 1 deletion docs/data_collection/api/datacollection_map_method.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ description: You can explore the map method of DataCollection in the documentati

# map()

@short: iterates through all items of the component
@short: iterates through all the items of the component

@signature: {'map(callback: (item: object, index?: number, array?: object[]) => any): object[];'}

9 changes: 5 additions & 4 deletions docs/data_collection/api/datacollection_reduce_method.md
Original file line number Diff line number Diff line change
@@ -8,20 +8,21 @@ description: You can explore the reduce method of DataCollection in the document

@short: reduces the array to a single value

@signature: {'reduce(callback: (acc: any, item: any) => any, acc: any): any;'}
@signature: {'reduce(callback: (acc: any, item: any, index?: number) => any, acc: any): any;'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 index не опционален.


@params:

- `callback: function` - a function that will be called for each item in the array. The function takes two parameters:
- `acc` - the <i>initialValue</i>, or the previously returned value of the function
- `callback: function` - a function that will be called for each item in the array. The function is called with the following parameters:
- `acc` - the *initialValue*, or the previously returned value of the function
- `item` - the current item of a data collection
- `index` - the index of the item
- `acc: any` - a value to be passed to the function as the initial value

@returns:
A single output value.

@example:
const total = component.data.reduce(function(acc, item) {
const total = component.data.reduce(function(acc, item, index) {
return acc + item.value;
}, 0);

2 changes: 1 addition & 1 deletion docs/data_collection/api/datacollection_remove_method.md
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ description: You can explore the remove method of DataCollection in the document
@example:
component.data.remove("2");
//or
component.data.remove(["2", "4"]);
component.data.remove([ "2", "4" ]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 в массивах так не делай, тут все было корректно. После "[" или "]" отступа нет


@descr:

11 changes: 8 additions & 3 deletions docs/data_collection/api/datacollection_resetfilter_method.md
Original file line number Diff line number Diff line change
@@ -8,12 +8,17 @@ description: You can explore the resetFilter method of DataCollection in the doc

@short: resets the active filters

@signature: {'resetFilter(config?: object): boolean;'}
@signature: {'resetFilter(config?: object, silent?: boolean): boolean;'}

@params:
- `config: object` - optional, specifies the parameters of resetting the active filters. If the config isn't specified or it is empty, all the filters except for those that have the **permanent** property in the configuration object will be reset. Can contain the following properties:
- `config: object` - optional, specifies the parameters of resetting the active filters. If the config isn't specified or it is empty, all the filters except for those that have the `permanent` property in the configuration object will be reset. Can contain the following properties:
- `id: string` - optional, the id of the filter to reset
- `permanent: boolean` - optional, *true* to reset all the active filters, including those that have the **permanent:true** property in their config
- `permanent: boolean` - optional, *true* to reset all the active filters, including those that have the `permanent:true` property in their config
- `silent: boolean` - optional, if *true*, the update of the DataCollection state won't trigger the component repainting, *false* by default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 выше уже писал. Этот параметр никак с перерисовкой не связан. Он просто делает метод "тихим", и не кидает события. Перерисовка может потребоваться, но это не должно быть в описании, и не является конечным назначением данного параметра.


:::info
Note that the use of the `silent` parameter may cause incorrect behavior of the method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 выше писал. Тут как раз можно и написать, что в определенных компонентах вам может потребоваться принудительная перерисовка методом paint().
На такие события, часто, завязана еще какая-то логика. Например перерасчет колонок или строк. Сделав метод тихим, мы не получим перерасчета, и paint() этого тоже не сделает.
Данный аргумент нужен, когда пользователю последовательно нужно что-то сделать, и потратить как можно меньше ресурсов, а на последнем вызове silent: false и тогда все расчеты и перерисовки применяются. Это кстати больше к update() применимо.

:::

@returns:
- `result: boolean` - *true*, if all the filters, including the permanent ones, have been reset; otherwise *false*
8 changes: 4 additions & 4 deletions docs/data_collection/api/datacollection_save_method.md
Original file line number Diff line number Diff line change
@@ -8,20 +8,20 @@ description: You can explore the save method of DataCollection in the documentat

@short: saves changes made in a data collection to the server side

@signature: {'save?: (url: string | IDataProxy) => void;'}
@signature: {'save(url: IDataProxy | string): void;'}

@params:
- `url: string | IDataProxy` - the URL of a server side or DataProxy with the URL configured
- `url: IDataProxy | string` - the URL of a server side or DataProxy with the URL configured

@example:
grid.data.save("http://userurl/");

//or
grid.data.save(new DataProxy({url:"http://userurl/"}));
grid.data.save(new DataProxy({ url:"http://userurl/" }));

@descr:

Each time the user changes data of the component, the **save()** method will make an AJAX call and expect the remote URL to save data changes.
Each time the user changes data of the component, the `save()` method will make an AJAX call and expect the remote URL to save data changes.
The method will send one of the following requests to the backend:

- `POST` - after adding new data into the component;
2 changes: 1 addition & 1 deletion docs/data_collection/api/datacollection_sort_method.md
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ description: You can explore the sort method of DataCollection in the documentat
- `as: function` - a function that specifies the type to sort data as
- `rule: function` - optional, a sorting rule; the function must have two parameters and return a number (-1,0,1)
- `config: object` - defines the parameter of sorting. It may contain one property:
- `smartSorting: boolean` - specifies whether a sorting rule should be applied each time after changing the data set
- `smartSorting: boolean` - optional, specifies whether a sorting rule should be applied each time after changing the data set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 заметил, что от метода к методу формат описания меняется. Иногда приводятся сигнатуры, как тут, а иногда нет. Если сигнатуры приводим. То тут нужен знак опциональности

- config?: object
      - smartSorting?: boolean

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хотелось бы видеть на всех страницах одинаковый подход.


@example:
grid.data.sort(
7 changes: 6 additions & 1 deletion docs/data_collection/api/datacollection_update_method.md
Original file line number Diff line number Diff line change
@@ -8,11 +8,16 @@ description: You can explore the update method of DataCollection in the document

@short: updates properties of the item

@signature: {'update?: (id: string | number, newItem: object) => void;'}
@signature: {'update?: (id: string | number, newItem: object, silent?: boolean) => void;'}

@params:
- `id: string | number` - the id of the item which needs to be updated
- `newItem: object` - a hash of properties which need to be updated
- `silent: boolean` - optional, if *true*, the update of the DataCollection state won't trigger the component repainting, *false* by default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 выше есть подробное описание данного аргумента. В целом перерисовка никак не связана с данным аргументом, все зависит от того, что мы делаем под капотом. Аргумент влияет на вызов событий. Для update() это наиболее актуально. Так как пользователь хочет, например, обновить тысячу элементов. И при каждом обновлении одного элемента будет происходить перерасчет и перерисовка компонента. Чтобы этого не делать. Он может вызвать событие на последнем элементе silent: false

Можно такой пример привести, он рабочий только для DataCollection. Для TreeCollection слегка изменится.

const lastIndex = data.getLength() - 1;

data.forEach((item, index) => {
    data.update(item.id, {
        param: "change param",
    }, index != lastIndex); // last update not silent
});


:::info
Note that the use of the `silent` parameter may cause incorrect behavior of the method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafanya23 смотрим комментарии выше

:::

@example:
component.data.update(123, { text:"New text" });
4 changes: 3 additions & 1 deletion docs/grid/data_loading.md
Original file line number Diff line number Diff line change
@@ -166,7 +166,9 @@ grid2.data.parse(state);

## Dynamic loading

{{pronote This functionality requires PRO version of the DHTMLX Grid (or DHTMLX Suite) package.}}
:::tip pro version only
This functionality requires PRO version of the DHTMLX Grid (or DHTMLX Suite) package.
:::

To enable dynamic data loading in Grid you need to:

8 changes: 4 additions & 4 deletions docs/grid/usage.md
Original file line number Diff line number Diff line change
@@ -263,7 +263,7 @@ grid.removeSpan("10", "a");

### Filtering data

You can filter grid data by the specified criteria with the help of the `filter()` method of [DataCollection](data_collection.md). The method takes as a parameter an object with the properties described below:
You can filter grid data by the specified criteria with the help of the `filter()` method of [DataCollection](data_collection.md). The method takes two parameters:

<table>
<tbody>
@@ -426,7 +426,7 @@ To get the current state of sorting data in Grid, use the [`getSortingStates()`]

~~~jsx
const state = grid.data.getSortingStates();
// -> [{by: "country", dir: "desc"}, {by: "population", dir: "desc"}]
// -> [{ by: "country", dir: "desc" }, { by: "population", dir: "desc" }]
~~~


@@ -547,7 +547,7 @@ It is possible to [set a predefined Grid configuration](#configuring-data-groupi

### Enabling data grouping

To use the row data grouping functionality in Grid, you need to apply the [`group`](grid/api/grid_group_config.md) configuration property of Grid. You can set the `group` property to *true* to enable grouping, or to specify it as a configuration object to [configure data grouping ](#configuring-data-grouping).
To use the row data grouping functionality in Grid, you need to apply the [`group`](grid/api/grid_group_config.md) configuration property of Grid. You can set the `group` property to *true* to enable grouping, or specify it as a configuration object to [configure data grouping](#configuring-data-grouping).

~~~jsx {5}
const grid = new dhx.Grid("grid_container", {
@@ -1025,7 +1025,7 @@ The method takes the following parameters:
- an `IGroupOrder` object that has the following properties:
- `by` - the field name or a function for user-defined grouping
- `map` - (optional) an object for data aggregation in a group, where the keys are field names, and the values can be:
- a tuple `[string, TAggregate]` that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from the `dhx.methods` helper
- a tuple `[string, TAggregate]` that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from the [`dhx.methods`](helpers/data_calculation_functions.md) helper
- a user-defined aggregation function `(i: IDataItem[]) => string | number`
- `summary` - (optional) specifies where the total row is rendered - at the `top` or at the `bottom` of the group
- `config` - (optional) the configuration of data grouping
Loading