ludo.dataSource.JSONTree

ludo.dataSource.


new ludo.dataSource.JSONTree()

Special collection class for tree structures.

Source:

Extends

Methods


addRecord(record) → {Object}

Add a record to data-source

Parameters:
Name Type Description
record
Inherited From:
Source:
Returns:

record

Type
Object

ascending() → {dataSource.JSONArray}

Set sort order to ascending

Inherited From:
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
Inherited From:
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
Inherited From:
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
Inherited From:
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

Inherited From:
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
Inherited From:
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
Inherited From:
Source:
Returns:

records

Type
Array

firstPage()

Go to first page

Inherited From:
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
Inherited From:
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.

getChildren(parent) → {Array|undefined}

Return children of parent with this id

Parameters:
Name Type Description
parent String

id

Source:
Returns:

children

Type
Array | undefined

getCount() → {Number}

Returns 1) If search is specified: number of records in search result, or 2) number of records in entire collection.

Inherited From:
Source:
Returns:

count

Type
Number

getData() → {Array}

Return data in collection

Inherited From:
Source:
Returns:
Type
Array

getNextOf(record) → {Object}

Returns next record of given record.

Parameters:
Name Type Description
record Object
Inherited From:
Source:
Returns:

next record

Type
Object

getPageCount() → {Number}

Return number of pages

Inherited From:
Source:
Returns:
Type
Number

getPageNumber() → {Number}

Return current page number

Inherited From:
Source:
Returns:

page

Type
Number

getPreviousOf(record) → {Object}

Returns previous record of given record

Parameters:
Name Type Description
record Object
Inherited From:
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
Inherited From:
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.

Inherited From:
Source:
Returns:
Type
dataSource.JSONArraySearch

getSelectedRecord() → {Object|undefined}

Return first selected record

Inherited From:
Source:
Returns:

record

Type
Object | undefined

getSelectedRecords() → {Array}

Return selected records

Inherited From:
Source:
Returns:

records

Type
Array

getSortedBy() → {String}

Return current sorted by column

Inherited From:
Source:
Returns:

column

Type
String

getSortOrder() → {String}

Return current sort order (asc|desc)

Inherited From:
Source:
Returns:

order

Type
String

isOnPage(pageNumber) → {Boolean}

True if on given page

Parameters:
Name Type Description
pageNumber Number
Inherited From:
Source:
Returns:
Type
Boolean

lastPage()

Go to last page

Inherited From:
Source:

next() → {Object}

Select next record. If no record is currently selected, first record will be selected

Inherited From:
Source:
Returns:

record

Type
Object

nextPage()

When paging is enabled, go to next page
fire nextPage event

Inherited From:
Source:

previous() → {Object}

Select previous record. If no record is currently selected, first record will be selected

Inherited From:
Source:
Returns:

record

Type
Object

previousPage()

When paging is enabled, go to previous page.
fire previousPage event

Inherited From:
Source:

remoteSearch(search)

Executes a remote search for records with the given data

Parameters:
Name Type Description
search String | Object
Inherited From:
Source:

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
Inherited From:
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
Inherited From:
Source:
Returns:

record

Type
Object | undefined

selectRecordIndex(index)

Select a specific record by index

Parameters:
Name Type Description
index number
Inherited From:
Source:

selectRecords(search) → {Array}

Select all records matching search

Parameters:
Name Type Description
search Object
Inherited From:
Source:
Returns:

records

Type
Array

selectTo(search)

Select records from current selected record to record matching search,

Parameters:
Name Type Description
search Object
Inherited From:
Source:
Example
collection.selectRecord({ country: 'Norway' });
     collection.selectTo({country: 'Denmark'});
     var selectedRecords = collection.getSelectedRecords();

setPageSize(size)

Parameters:
Name Type Description
size Number
Inherited From:
Source:

sort()

Resort data-source

Inherited From:
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
Inherited From:
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
Inherited From:
Source:
Returns:

success

Type
Boolean

updateRecord(search, updates) → {dataSource.Record}

Update a record

Parameters:
Name Type Description
search Object
updates Object
Inherited From:
Source:
Returns:

record

Type
dataSource.Record