Sencha stores as list data source - javascript

I'm having a hard time trying to resolve the following thing. I've a store
Ext.define('aBMin.store.Email', {
extend : 'Ext.data.Store',
requires : ['aBMin.model.Email'],
config : {
autoLoad : true,
model : 'aBMin.model.Email',
remoteFilter : true,
proxy : {
type : 'direct',
extraParams : {
filter : 'unassigned'
},
directFn : ClientemailTable.getListMobile,
config : {
paramsAsHash : true,
reader : {
type : 'json'
,rootProperty : 'result'
,successProperty: 'success'
,totalProperty: 'totalCount'
}
}
}
}
});
and the following json is being loaded to it:
[{"totalCount":8,"result":[],"tid":10,"method":"getListMobile","action":"ClientemailTable","type":"rpc"}]
Everything is being loaded properly except the 'totalCount' property to the store. When I'm trying to retrieve in in the Chrome's console, it prints 'null'.
NOTE: the 'result' property is loaded properly so in this case I'm presenting it as an empty array.
Ext.getStore('Email').getTotalCount()
> null
I use sencha touch 2.0. any ideas how to bing it?

Related

MongoDB - eval Vs. db.eval

I have a simple stored script in system.js collection called getAllNotes.
script code: function (x) { return db.notes.find(); }
notes is a collection holding the data I wish to extract.
eval('getAllNotes()') - works well and returns the data.
db.eval('getAllNotes()') - returns a JSON string with various configuration that has nothing to do
with my collection See below. Any idea? anyone understands the difference between executing eval and db.eval?
"_mongo" : {
"slaveOk" : false,
"host" : "EMBEDDED"
},
"_db" : {
"_mongo" : {
"slaveOk" : false,
"host" : "EMBEDDED"
},
"_name" : "test"
},
"_collection" : {
"_mongo" : {
"slaveOk" : false,
"host" : "EMBEDDED"
},
"_db" : {
"_mongo" : {
"slaveOk" : false,
"host" : "EMBEDDED"
},
"_name" : "test"
},
"_shortName" : "notes",
"_fullName" : "test.notes"
},
"_ns" : "test.notes",
"_query" : {
},
"_fields" : null,
"_limit" : 0,
"_skip" : 0,
"_batchSize" : 0,
"_options" : 0,
"_cursor" : null,
"_numReturned" : 0,
"_special" : false
eval takes a string of code that it executes.
db.eval, according to the docs, takes a function to call and a list of parameters to pass to that function. In other words, leave off the single quotes ' here:
db.eval(getAllNotes())
As for the difference between the two, the docs also state it:
The helper db.eval() in the mongo shell wraps the eval command. Therefore, the helper method shares the characteristics and behavior of the underlying command with one exception: db.eval() method does not support the nolock option.
Docs. Important stuff to learn things from before asking other people to do it for you.

Send additional data to KendoUI DataSource and use it in dataBound event

I want to get some additional data in the dataSource to use it in the dataBound event.
Here is transport I use in the grid:
"transport" : {
"read" : {
"url" : "f?p=120:0:701647109622339:PLUGIN=BC",
"dataType" : "json",
},
},
"pageSize" : 20,
"schema" : {
data : "row",
total : "total",
rowsdata : "rowsdata",
model : {
"id" : "doc_id",
}
},
I want to access rowsdata via $('#grid').data("kendoGrid").dataSource.data().rowsdata. Is it possible?
Here is a jsfiddle: http://jsfiddle.net/M8jvz/10/
In this particular case, I want to pass a list of permanently hidden columns into HideGrouped function
Here is the fiddle with the solution http://jsfiddle.net/Casufi/4ya83/2/
$('#grid').data("kendoGrid").dataSource.data()
Returns array. And what is that rowsdata inside your schema? Such configuration is not supported.
How to send addtional arguments to the server is covered here.
You can use dataSource.schema.data as an function to achieve what you want:
var dataSource = new kendo.data.DataSource({
"autoSync" : true,
"data" : l_json,
"pageSize" : 20,
"schema" : {
data : function(data){
data.rowsdata[0] = { hidden: 0, name: "name" }
return data.row;
},
...
Documentation here:
http://docs.kendoui.com/api/framework/datasource#configuration-schema.data

enhancedgrid filter plugin at server-side in Dojo

i am new to dojo,..struggling alot in this please help.....
i am using the filter plugin in EnhancedGrid in dojo....i am doing great at client side but coming to server side i dont know how to call the servlet and get the filtered rows in to grid please help in this .....
i tried something like this....
grid = new EnhancedGrid({
id : 'grid',
store : yourStore,
structure : layout,
rowSelector : '20px',
plugins : {
search : true,
pagination : {
pageSizes : [ "50", "100"],
description : true,
sizeSwitch : true,
pageStepper : true,
gotoButton : true,
maxPageStep : 2,
position : "bottom"
},
filter : {
closeFilterbarButton : true,
ruleCount : 5,
ruleCountToConfirmClearFilter:2,
itemsName : "rows",
isServerSide:true,
isSateful:true,
url:"http:myaddress:8080/GridExample/Filter",
setupFilterQuery: setupFilter
}
}
});
var setupFilter = function(commands, request){
if(commands.filter && commands.enable){
// some filter is defined and valid. You can modify the request object here.
}else{
// no filter is valid.
}
};
grid.placeAt("myGrid");
grid.startup();
}
});
First : have you load the Plugin correct?
dojo.require("dojox.grid.enhanced.plugins.Filter");
And maybe this helps you with your Problem:
http://dojotoolkit.org/reference-guide/1.8/dojox/grid/EnhancedGrid/plugins/Filter.html#introduction-to-server-side-filtering
Regards
UPDATE 1
Hi there!
I have to dig a little into the width of the Web but lately i think i found the answer to your question how to define the filter.
plugins: {
filter: {
isServerSide: true,
setupFilterQuery: function(commands, request){
if(commands.filter && commands.enable){
console.log(commands.filter);
request.query = {
"Name": "L*"
}
}
}
itemsName:'songs',
closeFilterbarButton: true,
ruleCount: 8
}
}
I grab this from here: https://bitbucket.org/dojo/dojox/src/64328839903b/grid/tests/enhanced/test_enhanced_grid_filter.html
This example defines a filter that searches the store for all Names that begins with the letter "L". With the other supported Operators you can define your own filter.
http://dojotoolkit.org/reference-guide/1.9/dojox/grid/EnhancedGrid/plugins/Filter.html#supported-operators
Hope this helps you!
Regards

Accessing XML elements in an ExtJS Store that are located outside of the defined records

In ExtJS 4, I have an XML Store that is defined as follows:
Ext.define('AC.store.GameWins',
{
extend : 'Ext.data.Store',
model : 'AC.model.GameWins',
autoLoad : true,
proxy :
{
type : 'ajax',
api :
{
read : 'data/gamewins.xml'
},
reader :
{
type : 'xml',
root : 'GameWins',
record : 'Game',
successProperty : 'success'
}
}
});
and an XML file that looks like this:
<GameWins>
<LastUpdated>2013-01-30 10:18:34</LastUpdated>
<Game ID="1" Name="GameName">
<WinDate>...</WinDate>
<WinAmount>...</WinAmount>
</Game>
<Game ID="1" Name="GameName">
<WinDate>...</WinDate>
<WinAmount>...</WinAmount>
</Game>
</GameWins>
It is easy enough to access the Game elements in a dataview using an XTemplate.
However, I have a problem accessing LastUpdated.. This is not part of the "record" that is defined in the Store. How can I access this element?
The raw data from the response is stored in the reader (in this case, the responseXML):
var xml = store.getProxy().getReader().rawData;

ExtJS: return total rows/records in json store

I have a json store that returns values in json format. Now I need to get the number of rows/records in the json string but when I use store.getCount() function it returns 0, but the combobox is populated with rows, and when I use store.length I get undefined, probably because its not an array anymore, its returning from store, which is calling php script. Anyways, whats the best approach for this problem?
Try this out:
var myStore = Ext.extend(Ext.data.JsonStore, {
... config...,
count : 0,
listeners : {
load : function(){
this.count = this.getCount();
}
}
Ext.reg('myStore', myStore);
and then use inside panels:
items : [{
xtype : 'myStore',
id : 'myStoreId'
}]
Whenever you need to get the count then you can simply do this:
Ext.getCmp('myStoreId').count
Your Json response from server, can be something like this...
{
"total": 9999,
"success": true,
"users": [
{
"id": 1,
"name": "Foo",
"email": "foo#bar.com"
}
]
}
Then you can use reader: {
type : 'json',
root : 'users',
totalProperty : 'total',
successProperty: 'success'
} in your store object.
As from docs if your data source provided you can call getTotalCount to get dataset size.
If you use ajax proxy for the store, smth like
proxy : {
type : 'ajax',
url : 'YOUR URL',
reader : {
type : 'json',
root : 'NAME OF YOUR ROOT ELEMENT',
totalProperty : 'NAME OF YOUR TOTAL PROPERTY' // requiered for paging
}
}
and then load your store like
store.load();
There will be sent Ajax asynchronous request, so you should check count in callback like this
store.load({
callback : function(records, operation, success) {
console.log(this.getCount()); // count considering paging
console.log(this.getTotalCount()); // total size
// or even
console.log(records.length); // number of returned records = getCount()
}
});

Categories