Constructor
new Store(opts)
Initialize the store. If you extend this method, you should call this._super()
Parameters:
Name |
Type |
Description |
opts |
object
|
The configuration object |
Properties:
Name |
Type |
Attributes |
Default |
Description |
rows |
array
|
<optional>
|
[]
|
the data rows |
useWebsocket |
boolean
|
<optional>
|
M_.App.useWebsocket
|
true if use websocket and not ajax |
rowsModel |
array
|
<optional>
|
[]
|
the model rows |
url |
string
|
<optional>
|
""
|
the model rows |
args |
object
|
<optional>
|
{}
|
arguments object to pass to each ajax request |
rootData |
string
|
<optional>
|
"data"
|
property where read data in json response |
currentSort |
array
|
<optional>
|
null
|
sort the store : ['name', 'asc'] ; the second is 'asc' or 'desc' |
model |
M_.Model
|
<optional>
|
null
|
the model to use |
primaryKey |
string
|
<optional>
|
""
|
the primary key |
limit |
number
|
<optional>
|
null
|
send 'limit' param to ajax request |
sortOnRemote |
boolean
|
<optional>
|
false
|
send 'sort' param to ajax request |
skip |
number
|
<optional>
|
0
|
send 'skip' param to ajax request |
unshiftRows |
array
|
<optional>
|
[]
|
add this rows in first position, just after load |
pushRows |
array
|
<optional>
|
[]
|
add this rows in last positions, just after load |
- Implements:
Example
// json store
var store = new M_.Store({
controller: this,
model: MT_Contacts,
url: "/contacts",
limit: 200,
listeners: [
['load',(store, data)=> {
// data are loaded
}]
]
}) ;
// ajax response would have the fields define in your model
{
data: [
{id:1, name:"David Miglior"},
{id:2, name:"Michael Miglior"}
]
}
Methods
addModel(row)
Parameters:
Name |
Type |
Description |
row |
type
|
|
addModels(rows)
Parameters:
Name |
Type |
Description |
rows |
type
|
|
addRow(row)
Parameters:
Name |
Type |
Description |
row |
type
|
|
addRows(rows)
Parameters:
Name |
Type |
Description |
rows |
type
|
|
count() → {type}
Returns:
-
Type
-
type
countTotal() → {type}
Returns:
-
Type
-
type
createEmptyRow() → {type}
Returns:
-
Type
-
type
deleteAll() → {type}
Returns:
-
Type
-
type
each(fn)
Parameters:
Name |
Type |
Description |
fn |
function
|
|
getIndexBy(field, val) → {type}
Parameters:
Name |
Type |
Description |
field |
type
|
|
val |
type
|
|
Returns:
-
Type
-
type
getIndexById(id) → {type}
Parameters:
Name |
Type |
Description |
id |
type
|
|
Returns:
-
Type
-
type
getRow(val) → {type}
Parameters:
Name |
Type |
Description |
val |
type
|
|
Returns:
-
Type
-
type
getRowAt(index) → {type}
Parameters:
Name |
Type |
Description |
index |
type
|
|
Returns:
-
Type
-
type
getRowBy(field, val) → {model}
Return the first model instance where the value of field equal val. The comparaison is do with ==, so "2"==2
Parameters:
Name |
Type |
Description |
field |
string
|
The searched field name |
val |
string
|
number
|
The value researched. |
Returns:
Return the model instance founded or null
-
Type
-
model
getRowByIndex(index) → {type}
Parameters:
Name |
Type |
Description |
index |
type
|
|
Returns:
-
Type
-
type
getRows() → {type}
Returns:
-
Type
-
type
getRowsBy(field, val) → {type}
Parameters:
Name |
Type |
Description |
field |
type
|
|
val |
type
|
|
Returns:
-
Type
-
type
isLoaded() → {Boolean}
Returns:
-
Type
-
Boolean
isLoading() → {Boolean}
Returns:
-
Type
-
Boolean
load(args, callback) → {type}
Parameters:
Name |
Type |
Description |
args |
type
|
|
callback |
function
|
|
Returns:
-
Type
-
type
reload(resetopt, moreArgsopt) → {type}
Parameters:
Name |
Type |
Attributes |
Default |
Description |
reset |
Boolean
|
<optional>
|
false
|
|
moreArgs |
type
|
<optional>
|
null
|
|
Returns:
-
Type
-
type
setKeysOnRows()
To document
setModels(rows)
Parameters:
Name |
Type |
Description |
rows |
type
|
|
setQuery(query)
Parameters:
Name |
Type |
Description |
query |
type
|
|
setRows(rows)
Parameters:
Name |
Type |
Description |
rows |
type
|
|
setSkip(skip)
Parameters:
Name |
Type |
Description |
skip |
type
|
|
sort(fields, direction, silently) → {type}
To document
Parameters:
Name |
Type |
Description |
fields |
Array
|
|
direction |
type
|
direction=1 ASC, direction=-1 DESC, direction=0 toggle |
silently |
type
|
|
Returns:
-
Type
-
type
Example
store.sort('co_name') ;
store.sort('co_name', 1) ;
store.sort([['co_name', 1], ['co_date',-1]]) ;
useModel()
To document