< Datasets | Table of content | Work with data on the server >
Before we start, we will create a copy of the catalog item and make a table to display data.
c = task.catalog.copy();
c.create_table($('#content'), {height: 820});
c.open(true);The open and apply methods can have callback and async parameters. If callback function is passed as a parameter or one of parameters is true, the request to the server is executed asynchronously, and after that, as the dataset is received, the callback function, if defined, will be executed.
c.open( function() {
c.warning(c.record_count())
})
c.open(true)Otherwise the request is executed synchronously.
c.open()It can have the following parameters:
options,callback,async.
Options parameter is an object that can have the following attributes:
expanded,fields,where,order_by,open_empty,funcs,group_by,limit,offset.
options = {
where: {value__range: [10, 20]},
fields: ['name', 'value'],
order_by: ['-value']
}
callback = function(item) {
item.warning('Total records: ' + item.record_count())
}
c.open(options, callback)The order of parameters doesn't matter. Some parameters can be omitted!
Let's demonstrate the func parameter:
c.open(
{
where: {value__range: [10, 20]},
fields: ['value'],
funcs: {value: 'sum'}
},
true
)There are auxiliary methods: set_where, set_fields, set_order_by. Calling these methods before the open method is similar to specifying corresponding parameters:
c.open({
where: {value__range: [10, 20]},
fields: ['name', 'value'],
order_by: ['-value']
},
callback
)It is the same as:
c.set_where( {value__range: [10, 20]} )
c.set_fields( ['name', 'value'] )
c.set_order_by( ['-value'] )
c.open(callback)After calling the open method, the action of these methods is canceled.
c.open(true)This can be used, for example, by setting filtering before calling the view method, which calls the open method in the on_view_form_created event handler.
task.catalog.set_where({value__range: [10, 60]})
task.catalog.view()There are three ways to define what records an item dataset will get from the database table:
- When the
openmethod is called specifywhereparameter, - Call the
set_wheremethod, before calling theopenmethod, - Use
filters.
Let's we create the value_ge filter for the value field, with filter type GE (greater than or equal to). Let's set its value to 50.
c.filters.value_ge.value = 50;
c.open(true);Filtering is performed as follows:
-
When
whereparameter is specified, it is always used, even if theset_wheremethod was called or the element hasfilterswhose values are set.c.set_where({value__ge: 10}); c.open({where: {value__ge: 90}}, true);
-
When
whereparameter is omitted the parameter passed to theset_wheremethod is used.c.set_where({value__ge: 10}); c.open(true);
-
When the
whereparameter is omitted and theset_wheremethod was not called,filtersare usedc.open(true)
To disable a filter set its value to null
c.filters.value_ge.value = null;
c.open(true);The where parameter of the open method is a dictionary, whose keys are names of the fields that are followed, after double underscore, by a filter symbol.
Note
For EQ (equal) filter the filtering symbol '__eq' can be omitted.
For example {id: 100} is equivalent to {id__eq: 100}.
For more information, see the Documentation.
< Datasets | Table of content | Work with data on the server >