new ludo.dataSource.JSONArray(config)
Data source collection
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object |
Properties
|
- Source:
Fires:
- ludo.dataSource.JSONArray#sort Fires on sort.event: Arguments: {String} sortedBy key
- ludo.dataSource.JSONArray#add Fires when a new record has been added to the collection.event: Arguments: {Object} record
- ludo.dataSource.JSONArray#deselect Fires when a record has been deselected, arguments.event: {Object} deselected record
- ludo.dataSource.JSONArray#select Fires when a record has selected, arguments.event: {Object} selected record
- ludo.dataSource.JSONArray#delete Fires when a record has been deleted, arguments.event: {Object} deleted record
- ludo.dataSource.JSONArray#page Fires on navigation to new page when paging is enabled.event: Arguments: {Number} page index
- ludo.dataSource.JSONArray#previousPage Fires when paging is enabled and navigating to current page -1.event: No arguments
- ludo.dataSource.JSONArray#nextPage Fires when paging is enabled and navigating to current page +1.event: No arguments
- ludo.dataSource.JSONArray#firstPage Fired when navigating to first page.event: No arguments
- ludo.dataSource.JSONArray#lastPage Fired when navigating to last page.event: No arguments
- ludo.dataSource.JSONArray#notLastPage Fired when navigating to a page which is not last page.event: No arguments
- ludo.dataSource.JSONArray#notFirstPage Fired when navigating to a page which is not first page.event: No arguments
- ludo.dataSource.JSONArray#event:change Fires when data has been updated or page navigation occurs.
Example
dataSource:{ url:'data-source/grid.php', id:'myDataSource', paging:{ size:12, remotePaging:false, cache:false, cacheTimeout:1000 }, searchConfig:{ index:['capital', 'country'] }, listeners:{ select:function (record) { console.log(record); } } }
Extends
- dataSource.JSON
Methods
-
addRecord(record) → {Object}
-
Add a record to data-source
Parameters:
Name Type Description record
- Source:
Returns:
record
- Type
- Object
-
ascending() → {dataSource.JSONArray}
-
Set sort order to ascending
- Source:
Returns:
this
- Type
- dataSource.JSONArray
Example
collection.by('country').ascending().sort();
-
by(column) → {dataSource.JSONArray}
-
Set sorted by column
Parameters:
Name Type Description column
String - Source:
Returns:
this
- Type
- dataSource.JSONArray
Examples
collection.by('country').ascending().sort(); or
collection.by('country').sort();
-
deleteRecord(search)
-
Delete ONE item from the data source.
Parameters:
Name Type Description search
Object | String - Source:
Example
// delete first record where property country matches "Norway" grid.getDataSource().deleteRecord({ country: 'Norway' }); // delete first record where record.uid = 'uid_ixrky8vq' grid.getDataSource().deleteRecord('uid_ixrky8vq'); // delete the first record in the data source var rec = grid.getDataSource().getData()[0]; grid.getDataSource().deleteRecord(rec);
-
deleteRecords(search)
-
Delete records matching search,
Parameters:
Name Type Description search
Object - Source:
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.JSONArray}
-
Set sort order to descending
- Source:
Returns:
this
- Type
- dataSource.JSONArray
Example
collection.by('country').descending().sort();
-
findRecord(search) → {Object|undefined}
-
Returns plain object for a record from search. To get a
{{#crossLink "dataSource.Record"}}{{/crossLink}} object
use {{#crossLink "dataSource.JSONArray/getRecord"}}{{/crossLink}}collection.find({ capital : 'Oslo' });
Parameters:
Name Type Description search
Object - Source:
Returns:
record
- Type
- Object | undefined
-
findRecords(search) → {Array}
-
Find specific records, example:
var records = collection.findRecords({ country:'Norway'});Parameters:
Name Type Description search
Object - Source:
Returns:
records
- Type
- Array
-
firstPage()
-
Go to first page
- Source:
-
getById(id) → {Object}
-
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.Parameters:
Name Type Description id
String | Number | Object - Source:
Returns:
record
- Type
- Object
Examples
var collection = new ludo.dataSource.JSONArray({ 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.JSONArray({ url : 'get-countries.php', primaryKey:['id', 'country'] }); var record = collection.getById({ id:1, country:'Japan' }); This is especially useful when you have a {{#crossLink "dataSource.JSONTree"}}{{/crossLink}} 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.
- Source:
Returns:
count
- Type
- Number
-
getData() → {Array}
-
Return data in collection
- Source:
Returns:
- Type
- Array
-
getNextOf(record) → {Object}
-
Returns next record of given record.
Parameters:
Name Type Description record
Object - Source:
Returns:
next record
- Type
- Object
-
getPageCount() → {Number}
-
Return number of pages
- Source:
Returns:
- Type
- Number
-
getPageNumber() → {Number}
-
Return current page number
- Source:
Returns:
page
- Type
- Number
-
getPreviousOf(record) → {Object}
-
Returns previous record of given record
Parameters:
Name Type Description record
Object - Source:
Returns:
previous record
- Type
- Object
-
getRecord(search) → {dataSource.Record|undefined}
-
Returns {{#crossLink "dataSource.Record"}}{{/crossLink}} object for a record.
If you want to update a record, you should
first get a reference to {{#crossLink "dataSource.Record"}}{{/crossLink}} and then call one
of it's methods.Parameters:
Name Type Description search
String | Object - Source:
Returns:
- Type
- dataSource.Record | undefined
Example
var collection = new ludo.dataSource.JSONArray({ url : 'get-countries.php', primaryKey:'country' }); collection.getRecord('Japan').set('capital', 'tokyo');
-
getSearcher() → {dataSource.JSONArraySearch}
-
Returns a {{#crossLink "dataSource.JSONArraySearch"}}{{/crossLink}} object which
you can use to filter a collection.- Source:
Returns:
- Type
- dataSource.JSONArraySearch
-
getSelectedRecord() → {Object|undefined}
-
Return first selected record
- Source:
Returns:
record
- Type
- Object | undefined
-
getSelectedRecords() → {Array}
-
Return selected records
- Source:
Returns:
records
- Type
- Array
-
getSortedBy() → {String}
-
Return current sorted by column
- Source:
Returns:
column
- Type
- String
-
getSortOrder() → {String}
-
Return current sort order (asc|desc)
- Source:
Returns:
order
- Type
- String
-
isOnPage(pageNumber) → {Boolean}
-
True if on given page
Parameters:
Name Type Description pageNumber
Number - Source:
Returns:
- Type
- Boolean
-
lastPage()
-
Go to last page
- Source:
-
next() → {Object}
-
Select next record. If no record is currently selected, first record will be selected
- Source:
Returns:
record
- Type
- Object
-
nextPage()
-
When paging is enabled, go to next page
fire nextPage event- Source:
-
previous() → {Object}
-
Select previous record. If no record is currently selected, first record will be selected
- Source:
Returns:
record
- Type
- Object
-
previousPage()
-
When paging is enabled, go to previous page.
fire previousPage event- Source:
-
remoteSearch(search)
-
Executes a remote search for records with the given data
Parameters:
Name Type Description search
String | Object - Source:
-
Search(search)
-
Filter collection based on given search term. To filter on multiple search terms, you should
get a reference to the {{#crossLink "dataSource.JSONArraySearch"}}{{/crossLink}} object and
use the available {{#crossLink "dataSource.JSONArraySearch"}}{{/crossLink}} methods to add
multiple search terms.Parameters:
Name Type Description search
String - Source:
Example
ludo.get('myCollection').search('New York'); // or with the {{#crossLink "dataSource.JSONArraySearch/add"}}{{/crossLink}} method var searcher = ludo.get('myCollection').getSearcher(); searcher.where('New York').execute(); searcher.execute();
-
selectRecord(search) → {Object|undefined}
-
Select the first record matching search
Parameters:
Name Type Description search
Object - Source:
Returns:
record
- Type
- Object | undefined
-
selectRecordIndex(index)
-
Select a specific record by index
Parameters:
Name Type Description index
number - Source:
-
selectRecords(search) → {Array}
-
Select all records matching search
Parameters:
Name Type Description search
Object - Source:
Returns:
records
- Type
- Array
-
selectTo(search)
-
Select records from current selected record to record matching search,
Parameters:
Name Type Description search
Object - Source:
Example
collection.selectRecord({ country: 'Norway' }); collection.selectTo({country: 'Denmark'}); var selectedRecords = collection.getSelectedRecords();
-
setPageSize(size)
-
Parameters:
Name Type Description size
Number - Source:
-
sort()
-
Resort data-source
- Source:
Returns:
void
-
sortBy(column, order) → {dataSource.JSONArray}
-
Sort by column and order
The second argument(order) is optional
Parameters:
Name Type Description column
String order
String - Source:
Returns:
this
- Type
- dataSource.JSONArray
Examples
grid.getDataSource().sortBy('firstname', 'desc'); which also can be written as
grid.getDataSource().by('firstname').descending().sort();
-
toPage(pageNumber) → {Boolean}
-
Go to a specific page
Parameters:
Name Type Description pageNumber
Number - Source:
Returns:
success
- Type
- Boolean
-
updateRecord(search, updates) → {dataSource.Record}
-
Update a record
Parameters:
Name Type Description search
Object updates
Object - Source:
Returns:
record
- Type
- dataSource.Record