Extjs Grid - callback store variable into pagingtoolbar - extjs

I init store variable in 'initComponent' of gridpanel like
initComponent: function() {
var store = Ext.create('Ext.data.Store', {
model: 'MyDataObject',
pageSize:_end,
proxy: {
type: 'ajax',
url: myurl,
reader: {
type: 'json',
totalProperty: 'total', // total data, see json output
root: 'results' // see json output
}
}
});
this.store = store;
this.callParent(arguments);
this.store.load({params:{start:_star, limit:_end}
});
I call store in pagingtoolbar like
dockedItems: [
{
xtype: 'pagingtoolbar',
dock: 'bottom',
store: this.store,
pageSize: _end,
displayInfo: true,
displayMsg: 'Displaying results {0} - {1} of {2}',
emptyMsg: 'No results'
}
]
In my gridpanel still have data but my bottom show "no results" like
I think problem is store: this.store,. How can i make it work thanks.

You can define a store like this
Ext.define('MyApp.store.MyDataStore', {
extend: 'Ext.data.Store',
model: 'MyDataObject',
storeId: 'myStoreId',
pageSize:_end,
proxy: {
type: 'ajax',
url: myurl,
reader: {
type: 'json',
totalProperty: 'total', // total data, see json output
root: 'results' // see json output
}
}
});
and then assign the myStoreId to the store-config of both the grid panel and the pagingtoolbar and the framework (the StoreManager) should create a single store which is assigned to both.
You can then either set autoload=true on your store or create a new store in initComponent of your grid and there do the loading manually.

I met this stranger problem yesterday,before I fixed this problem ,I guess the status were not synchronization of stores in both grid and pagingbar ,I spent a long to debug this problem with Firebug ,in other words the stores are not the same one ,they just the same instance of a store ,so you can fix this problem in two ways,the first is create a global variable of store,both them could share it the second is use bindStore method.for example support you have grid extension likes below
this.on('afterrender',function(){//this is grid itself
this.getBottomToolbar().bindStore(this.store)//set store of paggingtoolbar
},this);

I found the solution in here Remote paging grid in extjs
and the code must like:
this.store = store;
this.dockedItems = [{
xtype: 'pagingtoolbar',
store: this.store,
displayMsg: 'Displaying results {0} - {1} of {2}',
emptyMsg: 'No results',
dock: 'bottom',
displayInfo: true,
pageSize: 22
}];
this.callParent(arguments);
this.store.load({params:{start:0, limit:22}});

Related

Trying to use JSONStore in a combo

In our application we have a lot of name/value stores, and they are created at load time and put into a JSONStore like so :
Ext.create("Ext.data.JsonStore", {
data: data,
model: 'EM.model.controlUnit.CodeList',
storeId: "cl_" + tableId,
sorters: [{
sorterFn: aSorterFunction
}],
});
The model is pretty simple and looks like this :
Ext.define('EM.model.controlUnit.CodeList', {
extend: 'Ext.data.Model',
fields: [{
name: 'value', type: 'int'
}, {
name: 'label', type: 'string'
}, {
name: 'description', type: 'string'
}]
});
I thought stores were pretty interchangeable so I decided to use the store in the combo (There is no special combo store so I thought a JSONStore must be as good as a SimpleStore). I get the store like so :
var msDataStore = Ext.getStore("cl_t_cl_maritalstatus");
And use the store like so :
{
xtype: 'combo',
fieldLabel: 'Marital Status',
displayField: "label",
valueField: "value",
store: msDataStore
}
The combo is filled with the values from the store when I run the application, however, when I pop down the combo box, this error is thrown :
ext-debug-w-comments.js:9951 Uncaught
Ext.data.proxy.Server.buildUrl(): You are using a ServerProxy but have
not supplied it with a url.
I do not want any server proxy. These are simple locally stored name value collections.
Can JSONStores be used with combos?
If not. What is the best way to convert a JSONStore into something acceptable for the combo. I can chop, change, restructure the store object. But I just want to know if there is something simpler that I can do before going on some kind of long and pointless journey.
This problem is related 'proxy' property. Default proxy for JsonStore is 'ajax';
proxy: {
type : 'ajax',
reader: 'json',
writer: 'json'
}
You should override with 'memory' like that;
proxy: {
type: 'memory'
}
Your final store is;
Ext.create("Ext.data.JsonStore", {
data: data,
model: 'EM.model.controlUnit.CodeList',
storeId: "cl_" + tableId,
proxy: {
type: 'memory'
}
sorters: [{
sorterFn: aSorterFunction
}],
});
A JsonStore without URL is completely acceptable, but you have to make sure the combo does not trigger a load operation when clicking on the dropdown. This is done by adding to the combo definition the config option queryMode:'local':
{
xtype: 'combo',
fieldLabel: 'Marital Status',
displayField: "label",
valueField: "value",
queryMode: 'local',
store: msDataStore
}

PagingToolbar does not work

I am using PagingToolbar to filter my result search, I want do display 20 result per page, but in my grid still display all records.
The bbar in my grid
bbar: Ext.create('Ext.PagingToolbar',
store: store,
pageSize: 20,
displayInfo : true,
plugins: Ext.create('Ext.ux.ProgressBarPager', {})
}),
My Store
Ext.define('Mystore', {
extend: 'Ext.data.Store',
model: 'Mymodel',
pageSize: 20,
autoLoad: true,
remoteSort: true,
proxy: {
type: 'rest',
url: 'search',
reader: {
type: 'json',
root: 'root',
idProperty: 'id'
},
writer: {
type: 'json',
writeAllFields: true
}
}
});
Anybody could help me ??
Thanks.
Your /search REST service that provides the data for the store needs to support the start, limit, and/or page parameters so that the store can request a single page of results at a time.
To support the limit parameter, your service must limit the number of returned results to no more than the count specified in that parameter. You'd typically implement that by passing the limit value through to the database query you're using to provide the results.
Your Store must contain this parameter with start and limit and your backend need to use these parameters.
baseParams : {
start:0, limit:20
}
In java backend,
String startPage = request.getParameter("start");
String limits = request.getParameter("limit");
It's kind of filter for your grid.

baseParam for extjs paging

I am using datefields and comboboxes to make a selection to load a store. When the store is loaded into a grid i have a paging toolbar. So far so good.
When the user clicks on the next page the pagingtoolbar is not sending the data from the datefields with it. I read something about baseparams but this aint working.
I use EXTJS 4.1
This is my store:
NL.commListDetails = new Ext.data.Store({
model: 'stepDetails',
pageSize: 20,
loadMask: false,
sortOnLoad: true,
proxy: {
type: 'ajax',
url: detailURL,
startParam: '',
limitParam: '',
pageParam: '',
reader: {
type: 'json',
root: 'slaevents',
totalProperty: 'slaevents[0].totalCount'
}
},
baseParams: {fromDate:NL.startDate},
autoLoad: false
});
And here is the paging toolbar
bbar: Ext.create('Ext.PagingToolbar', {
store: NL.commListDetails,
displayInfo: true,
displayMsg: 'Displaying record {0} - {1} of {2}',
emptyMsg: "No records to display",
}),
I need to send fromDate, endDate with the paging. Both available in NL.startDate and NL.endDate. How can i send this when i click on next page?
There is no configuration of baseParams for the store. To send extra params you should use the extraParams configuration for the ajax proxy.
proxy: {
type: 'ajax',
....
extraParams: {fromDate:NL.startDate},
..
},
Also defining the params when creating the store will mean they are static, so they won;t change if you modify the datefields or comboboxes...
So a fix will be to listen to the change event on the combobox or datefield and reset the extra params:
change: function(this,value){
NL.commListDetails.getProxy().getExtraParams().comboName = value;
}
Edit
I stand corrected. There is a baseParams but it's on elementloader and that is called only when load is directly invoked, which i think is not the case for the paging toolbar which uses loadPage. I might be wrong on this one, but i'm using extraparams and it works ok.

ExtJS4: Value read in Store does not get populated in datafield

As part of my EXTJS 4 learning process, I am trying to establish a simple process of database connection - loading a value in a data Store - taking the value and placing it in a dataField.
The data is loaded fine from the php script and placed into the Store via a json call. (as confirmed through FireBug)
However, the dataField, does not seem to be able to load the value.
Here is what I have so far:
//Model definition
Ext.define('FingerModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'}
]
});
//Store Definition
var est_data = new Ext.data.Store({
model: 'FingerModel',
proxy: {
type: 'ajax',
url: 'finger.php',
extraParams: {opt: 'getName'},
reader: {
type: 'json',
root: 'results',
totalProperty: 'total'
}
},
autoLoad: true,
// turn off remote sorting
remoteSort: false
});
//Form definition
var fingerForm = Ext.create('Ext.form.Panel', {
width: 500,
title: 'Finger',
waitMsgTarget: true,
items: [{
xtype: 'fieldset',
title: 'Finger Form',
items: [{
xtype:'textfield',
fieldLabel: 'Location Name',
name: 'name'
}]
}]
});
fingerForm.getForm().loadRecord(FingerModel);
Anybody see anything obvious that I'm doing wrong?
Thanks in advance.
M.
Ext.form.field.Text does not have a 'store' property. How would it know which row of the store to use?
You should use Form.loadRecord() to load the model into the form, and it will set form fields with the same name as the model field names.

How to create dynamic tabs from a grid column on page load in extjs

I am generating data in a grid panel using json store. I have to generate tabs from the content of column 1 on page load . How can I generate those dynamic tabs from column 1?
Thanks! I am following the same approach but when I am looping through the tabs its not able to add tabs dynamically . I am sure my loop is working properly because I put an alert and its looping through all the records. My code is below...Please let me know where I am wrong..
var store = new Ext.data.JsonStore({
autoLoad: true,
url: '../json/test.json',
root: 'results',
fields:
[
'TIEBACK',
'GATE_TIME',
'TOTAL',
'STOP_DESC',
'DOOR'
],
sortInfo: {
field: 'TIEBACK', direction: 'ASC'
}
});
my tabpanel:
tabPanel = new Ext.TabPanel({
region: 'center',
deferredRender: false,
activeTab: 0,
items: [{
xtype: 'grid',
store: store,
//selModel: selModel,
columns: assignment,
stripeRows: true,
loadMask: true,
height: 200,
width: 200,
x: 490, y: 620,
title:'Assignment Status',
bbar: pagingBar
}]
});
loop:
store.on('load', function(){
store.each(function(re)
{
var tieback = re.get('TIEBACK');
//alert(tieback);
tabPanel.add(tieback);
});
});
So you have the JSON store, something like this
var store = new Ext.data.JsonStore({
// store configs
autoDestroy: true,
url: 'get-images.php',
storeId: 'myStore',
// reader configs
root: 'images',
idProperty: 'name',
fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
});
Then you can add a callback function to the store that gets fired once it loads. This is the documentation on that function
load : ( Store this, Ext.data.Record[] records, Object options )
so,
store.addListener(load, function(store, records, options){
// loop over records and dynamically create tabs here
});
So if you had a tabpanel like this
var tabs = new Ext.TabPanel({
renderTo:'tabs',
resizeTabs:true, // turn on tab resizing
minTabWidth: 115,
tabWidth:135,
enableTabScroll:true,
width:600,
height:250,
defaults: {autoScroll:true},
plugins: new Ext.ux.TabCloseMenu()
});
You can dynamically add tabs to it like this
tabs.add({
title: 'New Tab ' + (++index),
iconCls: 'tabs',
html: 'Tab Body ' + (index) + '<br/><br/>'
+ Ext.example.bogusMarkup,
closable:true
}).show();
That should be everything you need, more documentation can be found here.
http://www.sencha.com/deploy/dev/examples/tabs/tabs-adv.html

Resources