chart.DataProvider Class
Special data source for charts
Item Index
Methods
- addRecord
- ascending
- by
- deleteRecord
- deleteRecords
- descending
- findRecord
- findRecords
- getById
- getCount
- getData
- getNextOf
- getPageCount
- getPageNumber
- getPreviousOf
- getRecord
- getSearcher
- getSelectedRecord
- getSelectedRecords
- getSortedBy
- getSortOrder
- getSourceType
- hasData
- isOnPage
- lastPage
- load
- loadUrl
- next
- nextPage
- previous
- previousPage
- remoteSearch
- Search
- selectRecord
- selectRecordIndex
- selectRecords
- selectTo
- sendRequest
- sort
- sortBy
- toPage
- updateRecord
Properties
Attributes
Methods
addRecord
-
record
Add a record to data-source
Parameters:
-
record
Object
Returns:
ascending
()
dataSource.Collection
Set sort order to ascending
Returns:
Example:
collection.by('country').ascending().sort();
by
-
column
Set sorted by column
Parameters:
-
column
String
Returns:
Example:
collection.by('country').ascending().sort();
or
collection.by('country').sort();
deleteRecord
-
search
Delete a single record. Deletes first match when multiple matches found.
Parameters:
-
search
Object
Example:
grid.getDataSource().deleteRecord({ country: 'Norway' });
Will delete first found record where country is equal to Norway. It will fire a delete event if a record is found and deleted.
deleteRecords
-
search
Delete records matching search,
Parameters:
-
search
Object
Example:
grid.getDataSource().deleteRecords({ country: 'Norway' });
will delete all records from collection where country is equal to "Norway". A delete event will be fired for each deleted record.
descending
()
dataSource.Collection
Set sort order to descending
Returns:
Example:
collection.by('country').descending().sort();
findRecord
-
search
Returns plain object for a record from search. To get a dataSource.Record object use getRecord
collection.find({ capital : 'Oslo' });
Parameters:
-
search
Object
Returns:
findRecords
-
search
Find specific records, example: var records = collection.findRecords({ country:'Norway'});
Parameters:
-
search
Object
Returns:
getById
-
id
Return record by id or undefined if not found. Records are indexed by id. This method gives you quick access to a record by it's id. The method returns a reference to the actual record. You can use Object.clone(record) to create a copy of it in case you want to update the record but not make those changes to the collection.
Returns:
Example:
var collection = new ludo.dataSource.Collection({
url : 'get-countries.php',
primaryKey:'country'
});
var record = collection.getById('Japan'); // Returns record for Japan if it exists.
You can also define multiple keys as id
var collection = new ludo.dataSource.Collection({
url : 'get-countries.php',
primaryKey:['id', 'country']
});
var record = collection.getById({ id:1, country:'Japan' });
This is especially useful when you have a dataSource.TreeCollection where child nodes may have same numeric id as it's parent.
{ id:1, type:'country', title : 'Japan',
children:[ { id:1, type:'city', title:'Tokyo }]
By setting primaryKey to ['id', 'type'] will make it possible to distinguish between countries and cities.
getCount
()
Number
Returns 1) If search is specified: number of records in search result, or 2) number of records in entire collection.
Returns:
getData
()
Success:true, data:
Return data loaded from server
Returns:
getNextOf
-
record
Returns next record of given record.
Parameters:
-
record
Object
Returns:
getPreviousOf
-
record
Returns previous record of given record
Parameters:
-
record
Object
Returns:
getRecord
-
search
Returns dataSource.Record object for a record. If you want to update a record, you should first get a reference to dataSource.Record and then call one of it's methods.
Returns:
Example:
var collection = new ludo.dataSource.Collection({
url : 'get-countries.php',
primaryKey:'country'
});
collection.getRecord('Japan').set('capital', 'tokyo');
getSearcher
()
dataSource.CollectionSearch
Returns a dataSource.CollectionSearch object which you can use to filter a collection.
Returns:
getSourceType
()
Return data-source type(HTML or JSON)
Returns:
lastPage
()
Go to last page
load
()
Reload data from server Components using this data-source will be automatically updated
Returns:
next
()
Object
Select next record. If no record is currently selected, first record will be selected
Returns:
nextPage
()
When paging is enabled, go to next page fire nextPage event
previous
()
Object
Select previous record. If no record is currently selected, first record will be selected
Returns:
previousPage
()
When paging is enabled, go to previous page. fire previousPage event
remoteSearch
-
search
Executes a remote search for records with the given data
Search
-
search
Filter collection based on given search term. To filter on multiple search terms, you should get a reference to the dataSource.CollectionSearch object and use the available dataSource.CollectionSearch methods to add multiple search terms.
Parameters:
-
search
String
Example:
ludo.get('myCollection').search('New York');
// or with the dataSource.CollectionSearch/add method
var searcher = ludo.get('myCollection').getSearcher();
searcher.where('New York').execute();
searcher.execute();
selectRecord
-
search
Select a specific record
Parameters:
-
search
Object
Returns:
selectRecords
-
search
Select a collection of records
Parameters:
-
search
Object
Returns:
selectTo
-
search
Select records from current selected record to record matching search,
Parameters:
-
search
Object
Example:
collection.selectRecord({ country: 'Norway' });
collection.selectTo({country: 'Denmark'});
var selectedRecords = collection.getSelectedRecords();
sendRequest
-
service
-
arguments
-
data
Send a new request
sort
()
Resort data-source
Returns:
sortBy
-
column
-
order
Sort by column and order
The second argument(order) is optional
Returns:
Example:
grid.getDataSource().sortBy('firstname', 'desc');
which also can be written as
grid.getDataSource().by('firstname').descending().sort();
toPage
-
pageNumber
Go to a specific page
Parameters:
-
pageNumber
Number
Returns:
updateRecord
-
search
-
updates
Update a record
Returns:
Properties
Attributes
arguments
Array
Array of arguments to send to resource on server
Default: '' Here are some examples: Create a data source for server resource "Person", service name "load" and id : "1". You will then set these config properties:
Example:
"resource": "Person",
"service": "load",
"arguments": [1]
autoload
Boolean
Load data from external source on creation
Default: true
Fires event autoloadChange
Fires when the value for the configuration attribute autoload
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
object postData
Remote postData sent with request, example: postData: { getUsers: 1 }
Fires event object postDataChange
Fires when the value for the configuration attribute object postData
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
paging
Object
Use paging, i.e. only load a number of records from the server
Fires event pagingChange
Fires when the value for the configuration attribute paging
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
Example:
paging:{
size:10, // Number of rows per page
remotePaging:true, // Load only records per page from server, i.e. new request per page
cache : true, // Store pages in cache, i.e no request if data for page is in cache,
cacheTimeout:30 // Optional time in second before cache is considered out of date, i.e. new server request
}
searchConfig
Object
Configuration object for dataSource.CollectionSearch. This is the class which searchs and filters data in the collection.
Example:
searchConfig:{
index:['city','country'],
delay:.5
}
which makes the record keys/columns "city" and "country" searchable. It waits .5 seconds before the search is executed. This is useful when searching large collections and you want to delay the search until the user has finished entering into a search box.
selected
Object | String
Reference to record to select by default once data has been loaded
Default: undefined
shim
Object
Config of shim to show when content is being loaded form server. This config object supports two properties, "renderTo" and "txt". renderTo is optional and specifies where to render the shim. Default is inside body of parent view. "txt" specifies which text to display inside the shim. "txt" can be either a string or a function returning a string.
Example:
shim:{
renderTo:ludo.get('myView').getBody(),
txt : 'Loading content. Please wait'
}
renderTo is optional. Example where "txt" is defined as function:
shim:{
"txt": function(){
var val = ludo.get('searchField).getValue();
return val.length ? 'Searching for ' + val : 'Searching';
}
}
singleton
Boolean
Accept only one data-source of this type. You also need to specify the "type" property which will be used as key in the global SINGELTON cache By using singletons, you don't have to do multiple requests to the server
Fires event singletonChange
Fires when the value for the configuration attribute singleton
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
sortFn
Function
custom sort functions, which should return -1 if record a is smaller than record b and 1 if record b is larger than record a.
Default: {}
Example:
sortFn:{
'population':{
'asc' : function(a,b){
return parseInt(a.population) < parseInt(b.population) ? -1 : 1
},
'desc' : function(a,b){
return parseInt(a.population) > parseInt(b.population) ? -1 : 1
}
}
}
url
String
optional
Remote url. If not set, global url will be used
Fires event urlChange
Fires when the value for the configuration attribute url
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
Events
failure
Event fired when success parameter in response from server is false
Event Payload:
-
JSON
Objectresponse from server. Error message should be in the "message" property
-
this
ludo.dataSource.JSON
firstPage
Event fired when moving to first page
lastPage
Event fired when moving to last page
nextPage
Event fired when moving to next page
notFirstPage
Event fired when moving to a different page than last page
notLastPage
Event fired when moving to a different page than last page
previousPage
Event fired when moving to previous page
select
Event fired when a record is selected
Event Payload:
-
record
Object
Example:
...
listeners:{
'select' : function(record){
console.log(record);
}
}
servererror
Server error event. Fired when the server didn't handle the request
sort
Event fired when a data has been sorted, param example: { column:'country',order:'asc' }
Event Payload:
-
sortedBy
Object
toPage
Event fired when moving to a specific page