ComboCode
var applicationStore = new Ext.data.Store({
autoLoad : true,
url : 'index.php',
method : 'post',
baseParams : {action : 'getListApplication'},
idProperty : 'id',
sortInfo : {field : 'APPLICATION_REF', direction : 'ASC'},
reader : new Ext.data.JsonReader({
fields : [
{name: 'id', type: 'integer'},
{name: 'APPLICATION_ACTION', type: 'STRING'},
{name: 'APPLICATION_ID', type: 'integer'},
{name: 'APPLICATION_REF', type: 'string'},
{name: 'APPLICATION_LABEL', type: 'string'}
]
})
});
var formUserIDPannel = new Ext.form.ComboBox({
/*id : 'formUserIDPannel',
title : 'Liste des Applications',*/
renderTo : 'principalContainer',
/*frame : true,
padding : 0,
labelWidth : 95,*/
//items : [ {
id : 'combo',
xtype : 'combo',
fieldLabel : 'Application',
emptyText : 'Selectionnez une application',
anchor : '97%',
style : 'text-align:center;',
labelStyle : 'font-weight:bold;',
labelSeparator : '',
store : applicationStore,
tpl : '<tpl for="."><div ext:qtip="{APPLICATION_LABEL}" class="x-combo-list-item">{APPLICATION_REF}</div></tpl>',
displayField : 'APPLICATION_REF',
valueField : 'APPLICATION_LABEL',
mode : 'local',
triggerAction : 'all',
hiddenName : 'APPLICATION_ID',
hiddenValue : 'APPLICATION_ID',
selectODFocus: :true,
editable : false ,
listeners : {
'select': function(combo, record, index) {
}
// }]
}
});
/*var formUserIDPannel = new Ext.FormPanel({
id : 'formUserIDPannel',
title : 'Liste des Applications',
renderTo : 'principalContainer',
frame : true,
padding : 0,
labelWidth : 95,
items : [ {
xtype : 'combo',
id : 'CAD_ID_COMBO',
name : 'CAD_ID_COMBO',
fieldLabel : 'Application',
labelStyle : 'font-weight:bold',
anchor : '80%',
labelSeparator : '',
emptyText : 'Selectionnez une application',
store : new Ext.data.ArrayStore({
id : 0,
fields : [ 'id', 'value' ],
data : [ [ 1, 'TMS' ], [ 2, 'SOFT' ], [ 3, 'Autres' ], ]
}),
displayField : 'value',
valueField : 'id',
hiddenName : 'APPLICATION_ID',
hiddenValue : 'APPLICATION_ID',
mode : 'local',
triggerAction : 'all',
editable : true
} ]
});*/
var application = Ext.data.Record.create([
{name: 'id', type: 'integer'},
{name: 'APPLICATION_ACTION', type: 'string'},
{name: 'APPLICATION_ID', type: 'integer'},
{name: 'APPLICATION_REF', type: 'string'},
{name: 'CADENCE', type: 'integer'},
{name: 'PRICE', type: 'integer'}
]);
var gridStore = new Ext.data.GroupingStore({
reader : new Ext.data.JsonReader({fields: application}),
autoLoad : true,
url : 'index.php',
method : 'post',
baseParams : {action : 'getListApplication'},
sortInfo : {field: 'APPLICATION_REF', direction: 'ASC'}
});
var editor = new Ext.ux.grid.RowEditor({saveText : 'Sauvegarder', cancelText : 'Annuler'});
editor.on('canceledit', function(roweditor, cancel){
if(cancel)
{
if(grid.getSelectionModel().getSelected().get('APPLICATION_ACTION') == 'add')
{
gridStore.remove(grid.getSelectionModel().getSelected());
}
}
//Ext.getCmp('buttonAddApplication').setDisabled(false);
});
editor.on('validateedit', function(roweditor, change, record, rowIndex){
var setRecord = new Array();
if(record.get('APPLICATION_ACTION') == 'add')
{
setRecord = change;
}
else if(record.get('APPLICATION_ACTION') == 'update')
{
for(i in change)
{
setRecord.push({'key' : i, 'value' : change[i]});
}
}
sendAjax({
url : 'index.php',
showBusy : false,
params : {action : 'actionCadence', data : Ext.encode({actionBDD : record.get('APPLICATION_ACTION'), 'APPLICATION_ID' : record.get('APPLICATION_ID'), where : [{'key' : 'APPLICATION_ID', 'val':record.get('APPLICATION_ID')}], set : setRecord})},
method : 'post',
renderVar : 'responseJSON',
successCallback : {
functionName : function() {
//Ext.getCmp('buttonAddApplication').setDisabled(false);
Ext.alert.msg(responseJSON.title, responseJSON.message);
if(responseJSON.success == true)
{
if(Ext.getCmp('gridApplication').getSelectionModel().getSelected().get('APPLICATION_ACTION') == 'add')
{
if(Ext.isDefined(responseJSON.APPLICATION_ID))
{
Ext.getCmp('gridApplication').getSelectionModel().getSelected().set('APPLICATION_ID', responseJSON.APPLICATION_ID);
}
Ext.getCmp('gridApplication').getSelectionModel().getSelected().set('APPLICATION_ACTION', 'update');
}
}
else
{
if(Ext.getCmp('gridApplication').getSelectionModel().getSelected().get('APPLICATION_ACTION') == 'add')
{
Ext.getCmp('gridApplication').getStore().remove(Ext.getCmp('gridApplication').getSelectionModel().getSelected());
}
editor.stopEditing();
}
}
}
});
});
var reseizer = new Ext.ux.PanelResizer({minHeight: 250, maxHeight: 800});
var filters = new Ext.grid.GridFilters({
local : true,
filters:[
{type: 'string', dataIndex: 'APPLICATION_REF'}
]
});
var grid = new Ext.grid.GridPanel({
id : 'gridApplication',
store : gridStore,
width : 500,
height : 600,
selModel : new Ext.grid.RowSelectionModel({singleSelect : true}),
title : 'Détails des Applications',
renderTo : 'gridContainer',
autoHeight : false,
stripeRows : true,
frame : true,
loadMask : true,
enableColumnMove : false,
enableDragDrop : false,
autoExpandColumn : 'APPLICATION_REF',
plugins : [editor, reseizer,filters],
view : new Ext.grid.GroupingView({markDirty: false}),
//plugins :[filters, new Ext.ux.grid.GroupSummary()],
columns : [ {
id : 'APPLICATION_REF',
header : 'Tache/Opératrion ',
dataIndex : 'APPLICATION_REF',
width : 200,
sortable : true,
},{
header : 'Cadence',
dataIndex : 'CADENCE',
width : 150,
sortable : true,
editor : {
xtype : 'textfield',
allowBlank : true
}
},{
header : 'Prix',
dataIndex : 'PRICE',
width : 150,
sortable : true,
editor : {
xtype : 'textfield',
allowBlank : true
}
}
]
});
This is from ExtJS 4.2
Try Select without the quotes
listeners: {
select: function (combo, records) {
//do your stuff here
}
}
Related
We are using Extjs 5.x for building browser based single page application. Everything is working fine if simple model & store used by us. If we are trying to use any wrapper for proxy it's generate error during runtime after having sencha cmd build.
Here is the simple Model of Article:
Ext.define('Pos.model.Article', {
extend : 'Ext.data.Model',
alias : 'widget.Article',
idProperty : 'id',
fields : [
{ name : 'id', mapping : 'id', type : 'int' },
{ name : 'code', mapping : 'code', type : 'string'},
{ name : 'name', mapping : 'name', type : 'string'},
{ name : 'rate', mapping : 'rate', type : 'float' },
{ name : 'expireDate', mapping : 'expireDate', type : 'date' }
],
proxy : {
type : 'rest',
noCache : true,
limitParam : 'limit',
startParam : 'start',
url : '/pos/article',
reader : {
type : 'json',
rootProperty : 'data',
totalProperty : 'total',
successProperty : 'success',
messageProperty : 'message',
implicitIncludes: true
},
writer :{
type : 'json',
writeAllFields : true
},
simpleSortMode : true
}
});
Here is the simple Store of Article:
Ext.define('Pos.store.Articles', {
extend : 'Ext.data.Store',
model : 'Pos.model.Article',
idProperty : 'id',
autoLoad : false,
autoSync : false,
remoteSort : true,
remoteFilter : true,
pageSize : 25,
proxy : {
type : 'rest',
noCache : true,
limitParam : 'limit',
startParam : 'start',
url : '/pos/article/store',
reader : {
type : 'json',
rootProperty : 'data',
totalProperty : 'total',
successProperty : 'success',
messageProperty : 'message',
implicitIncludes: true
},
writer :{
type : 'json',
writeAllFields : true
},
simpleSortMode : true
},
sorters : [{
property : 'name',
direction: 'ASC'
}]
});
When we are using simple model and store it working fine. But our goal was removing boiler plate of code for this reason we are trying to build some wrapper method to remove the redundant codes. Here is the simple wrapper of proxy builder for your consideration:
var Cki=Cki||{};
;Cki.proxy||(function($){
var proxy = {
$package : 'Cki',
$class : 'Cki.proxy',
resolveUrl : function(action){
var ctxPath = '/pos/',
url = ctxPath + action;
return url;
},
getReader : function(){
var reader = {
type : 'json',
rootProperty : 'data',
totalProperty : 'total',
successProperty : 'success',
messageProperty : 'message',
implicitIncludes: true
};
return reader;
},
getWriter : function(){
var writer = {
type : 'json',
writeAllFields : true
};
return writer;
},
getRestProxy : function(url, noCache){
url = (typeof url === 'undefined') ? '' : url;
noCache = (typeof noCache === 'undefined') ? false : noCache;
var restProxy = {
type : 'rest',
noCache : noCache,
limitParam : 'limit',
startParam : 'start',
url : proxy.resolveUrl(url),
reader : proxy.getReader(),
writer : proxy.getWriter(),
simpleSortMode : true
};
return restProxy;
}
};
$.proxy = proxy;
}(Cki));
Once the wrapper of proxy builder method is ready, we could use it for wrapping the proxy inside model and store. Here is the wrapped Proxy Model:
Ext.define('Pos.model.Article', {
extend : 'Ext.data.Model',
alias : 'widget.Article',
idProperty : 'id',
fields : [
{ name : 'id', mapping : 'id', type : 'int' },
{ name : 'code', mapping : 'code', type : 'string'},
{ name : 'name', mapping : 'name', type : 'string'},
{ name : 'rate', mapping : 'rate', type : 'float' },
{ name : 'expireDate', mapping : 'expireDate', type : 'date' }
],
proxy : Cki.proxy.getRestProxy('article')
});
Here is the wrapped Proxy Store:
Ext.define('Pos.store.Articles', {
extend : 'Ext.data.Store',
model : 'Pos.model.Article',
idProperty : 'id',
autoLoad : false,
autoSync : false,
remoteSort : true,
remoteFilter : true,
pageSize : 25,
proxy : Cki.proxy.getRestProxy('article/store'),
sorters : [{
property : 'name',
direction: 'ASC'
}]
});
It's generate following error during runtime:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
http://localhost/pos/static/Ext-all.js Failed to load resource: the server responded with a status of 404 (Not Found)fetch # Ext-all.js:22
VM42:3 Uncaught TypeError: c is not a constructor
It's very difficult to find your error without debugging it, and I think it would be very difficult even with the code..
I'd suggest you to change the approach you are using to avoid boilerplate code.
I think the best way to achieve this is to extend the rest proxy class, putting there all the default configs.
Then you just use your proxy class in your store definition, passing just the url (that seems to be the only difference between models).
Example
Ext.define('My.data.proxy.Rest', {
extend: 'Ext.data.proxy.Rest',
alias : 'proxy.myrest',
noCache : true,
limitParam : 'limit',
startParam : 'start',
reader : {
type : 'json',
rootProperty : 'data',
totalProperty : 'total',
successProperty : 'success',
messageProperty : 'message',
implicitIncludes: true
},
writer :{
type : 'json',
writeAllFields : true
},
simpleSortMode : true
});
And in your store you will have
Ext.define('Pos.store.Articles', {
extend : 'Ext.data.Store',
model : 'Pos.model.Article',
idProperty : 'id',
autoLoad : false,
autoSync : false,
remoteSort : true,
remoteFilter : true,
pageSize : 25,
proxy : {
type: 'myrest',
url: '/pos/article/store',
},
sorters : [{
property : 'name',
direction: 'ASC'
}]
});
Hi I am in trouble with extjs 5 mvvm example. My store isn't recognized. I tried similliar solutions from stack but it still crashing.
Project structure:
structure
Code:
Message.js
Ext.define('Tgis.view.message.Message', {
extend : 'Ext.window.Window',
title: 'Wiadomosci',
requires : ['Tgis.view.message.MessageController'],
store: 'MessageStore',
alias : 'widget.message',
config : {
minHeight: 320,
minWidth:400,
bodyPadding : 10,
width : 500,
ghost : false,
bodyPadding : 10,
autoShow : true
},
items: [{
xtype:'panel',
layout : 'vbox',
items : [
{
xtype : 'mvvm-DateView' ,
flex : 1
},
{
xtype : 'mvvm-MessageView',
flex : 5
}]
}]});
Messagedate.js
Ext.define('Tgis.view.message.MessageDate', {
extend : 'Ext.grid.Panel',
xtype : 'mvvm-DateView',
store : 'MessageStore',
columns: [
{
text : 'Data',
dataIndex : 'date'
}
]});
MessageMaster.js
Ext.define('Tgis.view.message.MessageMaster', {
extend : 'Ext.form.Panel',
xtype : 'mvvm-MessageView',
requires : [
'Tgis.view.message.MessageViewModel'
],
title : 'Wiadomosci',
frame : true,
padding : 10,
viewModel : {
type : 'detailform' // references DetailViewModel
},
items : [
{
xtype : 'textfield',
bind : '{rec.message}',
fieldLabel : 'Tresc:'
},
{
xtype : 'hiddenfield',
bind : '{rec.id}'
}
]});
MessageModel.js
Ext.define('Tgis.view.message.MessageModel', {
extend : 'Ext.data.Model',
fields : [
{
name : 'date',
type : 'date'
},
{
name : 'message',
type : 'string'
},
{
name : 'id',
type : 'integer'
}
]});
Ext.define('Tgis.view.message.MessageStore', {
extend : 'Ext.data.Store',
model : 'Tgis.view.message.MessageModel',
storeId: 'MessageStore',
data : [
{
'date' : '28.05.1994',
'message' : 'lisa#simpsons.com',
'id' : '1'
}
]});
MessageController.js
Ext.define('Tgis.view.message.MessageController', {
extend : 'Ext.app.Controller',
init: function() {
this.control({
'mvvm-DateView': {
select : this.onGridSelect
}
});
},
onGridSelect : function(grid, record, index, eOpts) {
// grab a reference to the Detail view...
// we could have used a controller "ref", but those can also be problematic
var detailView = Ext.ComponentQuery.query('mvvm-DateView')[0];
//set the form's ViewModel binding
detailView.getViewModel().setData({ rec: record });
}});
MessageViewModel.js
Ext.define('Tgis.view.message.MessageViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.detailform',
data : {
rec : null
}});
Main.js
xtype: 'app-main',
controller: 'main',
viewModel: {
type: 'main'
},
layout: {
type: 'border'
},
items: [{
xtype: 'panel',
bind: {
title: '{name}'
},
region: 'west',
width: 250,
split: true,
defaultType : 'button',
layout : 'vbox',
items : [{
text : 'Wiadomości',
handler : 'onClickMessages'
},{
text : 'Wyczyść LC',
handler : 'onClearMessages'
}]
},{
region: 'center',
xtype: 'tabpanel',
items:[{
title: 'Tab 1',
html: '<h2>Content appropriate for the current navigation.</h2>'
}]
}]});
MainController.js
Ext.define('Tgis.view.main.MainController', {
extend: 'Ext.app.ViewController',
alias: 'controller.main',
onClickButton: function () {
Ext.Msg.confirm('Confirm', 'Are you sure?', 'onConfirm', this);
},
onConfirm: function (choice) {
if (choice === 'yes') {
//
}
},
onClickMessages : function(button) {
Ext.Ajax.request({
url : 'http://localhost:8080/Messagess/res',
method : 'GET',
success : function(response) {
var json = Ext.decode(response.responseText);
//var itemsArray = new Array();
/*for (var i = 0; i < json.data.length; i++) {
var date = new Date(json.data[i].date);
var messageTxt = Ext.create('Ext.form.field.TextArea', {
fieldLabel :date.toLocaleString(),
value : json.data[i].message,
editable : false,
grow : true,
width : '100%'
});
if (localStorage.getItem('date') != 'null')
itemsArray.push(messageTxt);
}
var checkbox = Ext.create('Ext.form.field.Checkbox', {
id : 'checkboxmessage',
boxLabel : 'Nie pokazuj ponownie'
});
itemsArray.push(checkbox);*/
Ext.create('Tgis.view.message.Message', {
//messagess: json.data
//Ext.getCmp('usernameID').setValue('JohnRambo');
/*items: itemsArray,
buttons : [{
xtype : 'button',
text : 'Zamknij',
handler : 'onCloseClick'
}]*/
})
}
});
},
onClearMessages : function(button) {
localStorage.setItem('date', '0');
}});
MainModel.js
Ext.define('Tgis.view.main.MainModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.main',
data: {
name: 'Tgis'
}});
Call store like this in view solved in my project
store: {
type: 'MessageStore'
}
You have defined a "store template" but not created a store instance.
If you want to create multiple stores of that type (e.g. one for each grid), do it like this:
xtype:'grid',
store:Ext.create('MyApp.store.SomeStore',{
...
}),
If you only want a single store of that type, just add the store to stores:[] array in Application.js and it should work.
I'm just started working with Ext js a week ago, and I would like to ask for help on how to make a relationship between two grid panel, I have the first panel to display categories and the second for sub-categories, so I want to : when I click on a category, it displays its subcategories in the second grid panel, and a message "please select a category if none is selected, for now I'm just displaying all subcategories in the second panel, here my code :
Ext.onReady(function() {
Ext.define('categorie', {
extend: 'Ext.data.Model',
fields: [
{name: 'id_categorie', type: 'string'},
{name: 'lib_categorie', type: 'string'},
],
idProperty: 'id_categorie'
});
Ext.define('sub-categorie', {
extend: 'Ext.data.Model',
fields: [
{name: 'id_sub-categorie', type: 'string'},
{name: 'lib_sub-categorie', type: 'string'},
{name: 'id_categorie', type: 'string' },
],
associations: [
{ type: 'belongsTo', model: 'categorie', primaryKey: 'id_sub-categorie', foreignKey: 'id_categorie' }
],
});
var categorieStore = Ext.create('Ext.data.Store', {
model: 'categorie',
pageSize : 15,
proxy: {
type: 'ajax',
url: 'ajax.php?mode=getCategories',
reader: {
type: 'json',
root: 'categories'
}
},
timeout : 90000,
extraParams : {
start : 0,
limit : 20
},
sorters: [ {
property : 'lib_categorie',
direction : 'ASC'
} ],
remoteSort : true,
autoDestroy : true,
simpleSortMode : true,
autoLoad: true
});
var subCategoriesStore = Ext.create('Ext.data.Store', {
model: 'sub-categorie',
pageSize : 15,
proxy: {
type: 'ajax',
url: 'ajax.php?mode=getSubCategories',
reader: {
type: 'json',
root: 'sub-categories'
}
},
timeout : 90000, // 90 secondes
extraParams : {
start : 0,
limit : 20
},
sorters: [ {
property : 'lib_sub-categorie',
direction : 'ASC'
} ],
remoteSort : true,
autoDestroy : true,
simpleSortMode : true,
autoLoad: true
});
var CategoriePanel = Ext.create('Ext.grid.Panel',{
title: 'Categories',
renderTo: 'categories_grid',
store: categorieStore,
columns: [
{
header : I18N.msgID,
tooltip : I18N.msgID,
align : 'left',
text: 'ID',
flex: 50,
dataIndex: 'id_categorie'
},
{
header : I18N.msgLib,
tooltip : I18N.msgLib,
align : 'left',
text: 'Lib',
flex: 50,
dataIndex: 'lib_categorie'
},
],
width: 400,
});
var subCategoriePanel = Ext.create('Ext.grid.Panel',{
title: 'subCategories',
renderTo: 'subcategories_grid',
store: subCategoriesStore,
columns: [
{
header : I18N.msgIDs,
tooltip : I18N.msgIDs,
align : 'left',
text: 'IDs',
flex: 50,
dataIndex: 'id_sub-categorie'
},
{
header : I18N.msgLibs,
tooltip : I18N.msgLibs,
align : 'left',
text: 'Libs',
flex: 50,
dataIndex: 'lib_sub-categorie'
},
],
width: 400,
});
You must add a listener to your categories grid:
listeners: {
itemclick: function ( this, record, item, index, e, eOpts ) {
// Select your catergory, find subcategories and load subcategories in your subcategories grid
}
}
I need to get some data with making ajax request and load the grid (which is empty first) with this data but even i get the data i couldnt load it to the grid.
What i'm doing wrong?
Here is my grid :
var gridFlightForms = Ext.create('Ext.grid.Panel', {
id : 'gridFlightForms',
store : storeFlightFormList,
width : '100%',
height : 300,
collapsible : false,
multiSelect : false,
autoScroll : true,
disableSelection : false,
monitorWindowResize : true,
viewConfig : {
stripeRows : true,
enableTextSelection : true
},
title : 'Flight Forms ',
bbar : Ext.create('Ext.ux.statusbar.StatusBar', {
id : 'gridData-statusbar',
defaultText : '',
defaultIconCls : 'default-icon',
}),
verticalScroller : {
xtype : 'paginggridscroller',
},
columns : [ {
text : '<fmt:message key="common.number.text" />',
xtype : 'rownumberer',
width : 40,
sortable : false
}, {
text : 'Form Id',
menuDisabled : true,
dataIndex : 'formId',
width : 150,
}, {
text : 'Form no',
menuDisabled : true,
dataIndex : 'formNo',
width : 150,
}, {
text : 'Form Type',
menuDisabled : true,
dataIndex : 'formType',
width : 150,
}, {
text : 'Flight Id',
menuDisabled : true,
dataIndex : 'flightId',
width : 150,
}, {
text : 'Revision',
menuDisabled : true,
dataIndex : 'revision',
width : 150,
}, {
text : 'IsLiex',
menuDisabled : true,
dataIndex : 'isLiex',
width : 150,
}, {
text : 'IsPrimary',
menuDisabled : true,
dataIndex : 'isPrimary',
width : 150,
}, {
text : 'Step Number',
menuDisabled : true,
dataIndex : 'stepNumber',
width : 150,
} ]
});
and my store :
var storeFlightFormList = Ext.create('Ext.data.Store', {
model : flightListModelName,
autoLoad : false,
proxy : {
type : 'ajax',
actionMethods : {
read : 'POST'
},
reader : {
type : 'json',
root : 'data'
},
api : {
read : flightFormListUrl
}
},
listeners : {
load : function(store, records) {
}
}
});
and that part is making post and try to load data to grid. I think this part is wrong.
Actually i can see data in resp.data when i debug it, but i cant store it as i mentioned before.
postDataAsParamsINN(
{flightId : flightId},flightFormListUrl,function(resp) {
gridFlightForms.setLoading(true,true);
storeFlightFormList.loadRawData(resp.data,false);
});
Ext.getCmp('gridFlightForms').getStore().load();
I'm pretty new at extjs, thanks in advance.
I'm not quite sure what postDataAsParamsINN is supposed to be doing, you should not need to be loading the data in yourself.
This fiddle demonstrates a working grid that uses a JSON store.
Here is the code:
Ext.application({
name: 'Fiddle',
launch: function() {
var store = Ext.create('Ext.data.JsonStore', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
autoLoad: true,
proxy: {
type: 'ajax',
url: 'data1.json',
reader: {
type: 'json',
rootProperty: 'characters'
}
},
listeners: {
load: function() {
console.log(this);
}
}
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
}
});
Once you've bound your store to the grid it automatically fills the grid with whatever information is loaded into the store and refreshes when the store is updated.
I have this json string look like:
[{
"totalCount" : 134
}, {
"items" : [{
"id" : 1669,
"check" : false,
"name" : "1800mm趟门衣柜",
"part_number" : "DP101669"
}, {
"id" : 1670,
"check" : false,
"name" : "1800mm趟门衣柜",
"part_number" : "DP101670"
}, {
"id" : 1671,
"check" : false,
"name" : "2118mm趟门衣柜",
"part_number" : "DP101671"
}, {
"id" : 1672,
"check" : false,
"name" : "2118mm趟门衣柜",
"part_number" : "DP101672"
}, {
"id" : 1673,
"check" : false,
"name" : "1800mm趟门衣柜",
"part_number" : "DP101673"
}, {
"id" : 1674,
"check" : false,
"name" : "1800mm趟门衣柜",
"part_number" : "DP101674"
}, {
"id" : 1675,
"check" : false,
"name" : "1800mm趟门衣柜",
"part_number" : "DP101675"
}, {
"id" : 1676,
"check" : false,
"name" : "1800mm趟门衣柜",
"part_number" : "DP101676"
}, {
"id" : 1677,
"check" : false,
"name" : "2118mm趟门衣柜",
"part_number" : "DP101677"
}, {
"id" : 1678,
"check" : false,
"name" : "2118mm趟门衣柜",
"part_number" : "DP101678"
}
]
}
]
and my store look like:
var item_store = Ext.create('Ext.data.Store', {
model:'ItemModel',
autoLoad: true,
pageSize: 5,
proxy: {
type: 'ajax',
reader: {
type:'json',
root: 'items',
totalProperty: 'totalCount'
},
url: 'item_access.jsp?fullpage=true&item_cat=167&group_id='+groupId
}
});
but it cant read the root node for the store ,now my table look like that:
only with two blank row,
look like are node totalCount and items:
so how should I config the reader to read that string??
that is my grid:
var itemPanel=Ext.create('Ext.grid.Panel', {
id: 'item-panel',
title: '产品',
store: item_store,
columns: [
{ header: 'id', dataIndex: 'id' , flex: 1 },
{ header: 'part_number', dataIndex: 'part_number' , flex: 2 },
{ header: 'name', dataIndex: 'name', flex: 3 },
{ xtype: 'checkcolumn',header: '可见', dataIndex: 'check' , flex: 2 ,
listeners:{
checkchange: function(col, idx, isChecked) {
var view = itemPanel.getView(),
record = view.getRecord(view.getNode(idx));
postData(record.get('id'),"ITEM",isChecked);
}
}
}
],
region: 'center',
layout: 'card',
// paging bar on the bottom
bbar: Ext.create('Ext.PagingToolbar', {
store: item_store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display",
items:[
'-', {
text: 'Show Preview',
pressed: pluginExpanded,
enableToggle: true,
toggleHandler: function(btn, pressed) {
var preview = Ext.getCmp('gv').getPlugin('preview');
preview.toggleExpanded(pressed);
}
}]
}),
});
my model:
Ext.define('ItemModel', {
extend : 'Ext.data.Model',
idProperty : 'id',
fields : [{
name : "name",
convert : undefined
}, {
name : "id",
type : types.INT
}, {
name : "part_number"
}, {
name : "check",
type : types.BOOLEAN
}
]
});
In the 4.x series you can pass functions for both the root/total:
totalProperty: function(data) {
return data[0].totalCount
},
root: function(data) {
return data[1].items
}
You may change the data structure if possible :
{ "totalCount": 134, "items": [] }
Edit
I have setup a quick test using ext-all-debug.js from version 4.2.0.663, the same as in your JsFiddle. At first glance, the problem comes from the line 41343 :
root = Ext.isArray(data) ? data : me.getRoot(data);
At this point getRoot - which refers to the root property somehow - is not called because data is an array. This is not a bug. I rather think that you misuse the JSON reader which is designed to consider an array not as a configuration structure, but as a record list. Sorry for repeating this but you'd better replace the array with an object as mentionned above. If it's not possible you'll have to bring some changes to the framework in order to make it suit your needs.