RowEditing with Combobox - changes (click row editing) - should be displayed "displayField" - extjs

RowEditing with Combobox - changes (click row editing) shown "id",
should be displayed "displayField"
pic - i65.fastpic.ru/big/2014/0724/46/d7cef656f6d993bc17657486ba5b6b46.gif
when editing a row - to display the value of the field displayfield from storeServer
now displays dataindex from store
Ext.define('ModelLib', {
extend: 'Ext.data.Model',
fields: [
'trID',
'trName'
]
});
var storeServer = Ext.create('Ext.data.Store', {
autoDestroy: true,
model: 'ModelLib',
proxy: {
type: 'ajax',
api: {
read: '/api.php?lib=server&act=get'
},
reader: {
type: 'json',
root: 'fields',
idProperty: "trID"
}
},
sorters: [{
property: 'trID',
direction: 'ASC'
}]
});
storeServer.load();
Ext.define('ModelMainobjects', {
extend: 'Ext.data.Model',
fields: [
{name: 'trServerID', type: 'int'}
]
});
var store = Ext.create('Ext.data.Store', {
// destroy the store if the grid is destroyed
autoDestroy: true,
autoSync : true,
model: 'ModelMainobjects',
proxy: {
type: 'ajax',
api: {
read: '/api.php?lib=mainobjects&act=get',
update: '/api.php?lib=mainobjects&act=update'
},
reader: {
type: 'json',
root: 'fields',
idProperty: "trID"
},
writer: {
type: 'json'
}
},
sorters: [{
property: 'trID',
direction: 'ASC'
}]
});
store.load();
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false
});
var rowRenderer = function(val) {
var rec = storeServer.findRecord('id', val);
return rec !== null ? rec.get("trName") : ''
};
var grid = Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{
header: 'Сервер',
dataIndex: 'trServerID',
renderer: rowRenderer,
editor: {
xtype: 'combobox',
store: storeServer,
queryMode: 'local',
displayField: 'trName',
valueField: 'trID'
}
}],
width: 600,
height: 400,
plugins: [rowEditing]
});

Related

Extjs store insert roweditor

The setup:
I have a grid with a roweditor plugin. On the toolbar I have a "add new" button to insert a new row.
The problem:
When I'm trying to add a new record my store.insert(0, rec), doesn't seems to add the record on the 0 index.
My view:
Ext.define("app.view.partners.Partners",{
extend: "Ext.grid.Panel",
alias: 'widget.partners',
requires: [
"Admin.view.partners.PartnersController",
"Admin.view.partners.PartnersModel"
],
height: 700,
controller: "partners",
viewModel: {
type: "partners"
},
bind: {
store: '{partners}'
},
title: "Partners List",
columns: [
{ header: 'id', dataIndex: 'id', hidden: true},
{ header: 'Partner', dataIndex: 'Partner', flex: 3,
editor: {
xtype: 'textfield',
allowBlank: false
}
}
],
tbar: [{
text: 'Add record',
iconCls: 'fa fa-plus-square green',
handler: 'onAddClick'
}],
selType: 'rowmodel',
plugins: [{
ptype: 'rowediting',
clicksToMoveEditor: 1,
pluginId: 'partnersRowEditingPlugin',
autoCancel: false,
listeners: {
edit: 'onEditClick',
canceledit: function(rowEditing, context) {
// Canceling editing of a locally added, unsaved record: remove it
if (context.record.phantom) {
context.store.remove(context.record);
}
}
}
},{ptype: 'bufferedrenderer'},
{ptype: 'gridfilters'}
]
});
My viewmodel:
Ext.define('app.view.partners.PartnersModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.partners',
stores: {
partners:{
model: 'app.model.Partners',
storeId: 'partners',
autoLoad: true,
sorters: [{
property: 'id',
direction: 'DESC'
}],
proxy:{
type: 'ajax',
// load remote data using HTTP
url: 'read.php',
reader: {
type: 'json',
idProperty: 'id',
rootProperty: 'data',
totalProperty:'total'
}
}
}
}
});
and in the viewcontroller:
onAddClick: function(){
var rec = new app.view.partners.PartnersModel({});
//var rec = new new Admin.model.Partners({});
this.isNewRecord = true;
var store = this.getView().getStore();
store.insert(0, rec);
this.getView().getPlugin(controllerName + 'RowEditingPlugin').startEdit(0,0);
}
here is a console.log after store.insert(0,rec)
It appears that the store does the insert, but it is inserted last. I can see it added on the grid as the last record.
I don't know what I am doing wrong.

EXTJS 4 sortInfo is not working in JsonStore

Ext.define('RouteSeqModel', {
extend: 'Ext.data.Model',
fields: [{name: '_id', type: 'number'}, {name: 'Route_Seq' , type: 'int'},'Location_Name','Location_ID','Route_ID']
});
var RouteSeqStore = Ext.create('Ext.data.JsonStore', {
model: 'RouteSeqModel',
storeId: 'RouteSeqStore',
autoLoad: false,
sortInfo: { field: "Route_Seq", direction: "ASC" },
proxy: {
type: 'ajax',
url: 'get-routeseq.php',
api: {
create: 'insert-routeseq.php',
update: 'update-routeseq.php',
},
actionMethods: 'POST',
baseParams: {
_id : 0,
},
reader: {
type: 'json',
idProperty: '_id'
},
writer: {
type: 'json',
id: '_id'
}
}
});
Ext.define('MyApp.view.MyGridPanelRouteSeq', {
extend: 'Ext.grid.Panel',
id:'MyGridPanelRouteSeq',
alias: 'widget.mygridpanelrouteseq',
renderTo: Ext.getBody(),
height: window.innerHeight,
width: window.innerWidth/2,
title: 'Route Sequence Setting',
sortableColumns: false,
store: RouteSeqStore,
columns: [
{
xtype: 'gridcolumn',
width: 70,
dataIndex: 'Route_Seq',
text: 'Sequence'
},
{
xtype: 'gridcolumn',
width: 160,
dataIndex: 'Location_Name',
text: 'Location Name'
}]
})
Sequence is read the data from Route_Seq, but the column is still not sorting yet.
i have no idea how come the grid is still not sorting..why?
Where did you get sortInfo from? It's not a valid store config.
You want:
sorters: [{
property: 'Route_Seq',
direction: 'DESC'
}]

Extjs 4 combo xml store load?

I am using ext-4.2.1, below is the code. It has two problems, (1) buildCategoryStore(), combo can't find the store. (2) the below is the xml data, looks like the store xml reader doesn't work, how to set up the xml root ?
Thanks
Ext.define('App.view.QuestionForm',{
extend : 'Ext.form.Panel',
alias : 'widget.QuestionForm',
requires : [],
initComponent : function(){
var me = this;
me.items = me.buildItems();
me.callParent();
},
buildCategoryStore: function(){
var CategoryStore = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: ['id','name'],
proxy: {
type: 'ajax',
url: 'rs/question/getAllCategories',
reader: {
type:'xml',
root: 'CategoryList'
}
},
storeId: 'CategoryStore',
root: 'CategoryList'
});
return CategoryStore;
},
buildItems : function(){
return [
{
xtype: 'combo',
anchor: '100%',
fieldLabel : 'Category',
store: buildCategoryStore(),
name: 'category',
mode: 'local',
multiSelect: false
},
];
},
}
});
xml data :
<CategoryList>
<Category>
<active>Y</active>
<id>1000</id>
<name>Life</name>
<versionNum>0</versionNum>
</Category>
<Category>
<active>Y</active>
<id>1001</id>
<name>Career</name>
<versionNum>0</versionNum>
</Category>
</CategoryList>
I've fixed up your code. The important parts are you need to call this.foo() and you need to specify the record param for the reader.
Ext.define('App.view.QuestionForm', {
extend: 'Ext.form.Panel',
alias: 'widget.QuestionForm',
requires: [
'Ext.data.Store'
],
initComponent: function() {
this.items = this.buildItems();
this.callParent();
},
buildCategoryStore: function() {
return new Ext.data.Store({
autoLoad: true,
fields: ['id', 'name'],
proxy: {
type: 'ajax',
url: 'rs/question/getAllCategories',
reader: {
type: 'xml',
record: 'Category'
}
}
});
},
buildItems: function() {
return [{
xtype: 'combo',
anchor: '100%',
fieldLabel: 'Category',
store: this.buildCategoryStore(),
name: 'category',
mode: 'local',
multiSelect: false,
valueField: 'id',
displayField: 'name'
}];
}
});

ExtJs- TreeStore AJAX Proxy not sending request to Server or TreeStore is not loading

Ext js TreeStore is not loading
Ext.ns('App');
Ext.onReady(function() {
Ext.QuickTips.init();
App.PPPExplorer.init();
});
App.PPPExplorer = {
// Initialize application
init : function(serverCfg) {
this.PPP = this.createPPP();
},
createPPP : function() {
// Set up a model to use in our Store
Ext.define('Summary', {
extend: 'Ext.data.Model',
fields: [
{name: 'pid', type: 'string'}
]
});
var myStore = Ext.create('Ext.data.TreeStore', {
model: 'Summary',
storeId:'myStore',
proxy: {
type : 'ajax',
method: 'GET',
url: '/Explorer.do?method=getPPP&search=true',
reader: {
type: 'json'
},
root: {
pid: 'src',
text:'test',
expanded: true
},
},
autoLoad: true
});
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: myStore,
// rootVisible: true,
renderTo: 'Explorer',
columns: [{
xtype: 'treecolumn', //this is so we know which column will show the tree
text: 'Reference',
flex: 2,
sortable: true,
dataIndex: 'pid',
locked: true
}]
});
}
}
I am using Ext js 4.2 Version
I have used treeStore, treePanel in the above code, somehow Proxy call is not sent to Server. There was no error message in the console
Thanks in advance
Root definition should be inside TreeStore definition as follows (it's on the proxy declaration now):
var myStore = Ext.create('Ext.data.TreeStore', {
model: 'Summary',
storeId: 'myStore',
proxy: {
type: 'ajax',
method: 'GET',
url: '/Explorer.do?method=getPPP&search=true',
reader: {
type: 'json'
}
},
autoLoad: true,
root: {
pid: 'src',
text: 'test',
expanded: true
}
});
That way your code works, you can see it here

load store with parameter selected on another grid

I have this code :
Ext.define('MyDesktop.Opport', {
extend: 'Ext.ux.desktop.Module',
requires: [
'Ext.data.ArrayStore',
'Ext.util.Format',
'Ext.grid.Panel',
'Ext.grid.RowNumberer',
/***********************/
'Ext.grid.*',
'Ext.data.*',
'Ext.panel.*'
/***********************/
],
id:'opp',
createWindow : function(){
var storeop = Ext.create('Ext.data.JsonStore', {
proxy: {
type: 'ajax',
url: 'PHP/afficherop.php',
reader: {
type: 'json', // format fichier : JSON
root: 'enregistrements', // D?but des donn?es
idProperty: 'id' // cl? primaire
}
},
fields: ['id','date','infos','idProd','idcl']
});
var storecl = Ext.create('Ext.data.JsonStore', {
proxy: {
type: 'ajax',
url: 'PHP/afficher.php',
reader: {
type: 'json', // format fichier : JSON
root: 'enregistrements', // D?but des donn?es
idProperty: 'id' // cl? primaire
}
},
fields: ['id','type','nom','prenom','mat']
});
storecl.load();
var desktop = this.app.getDesktop();
var win = desktop.getWindow('opp');
/*******************/
if(!win){
win = desktop.createWindow({
id: 'opp',
title:'Opportunités',
width:500,
height:480,
iconCls: 'bogus',
animCollapse:false,
constrainHeader:true,
layout: 'border',
align: 'center',
items: [
{
xtype: 'grid',
flex: 1,
split: true,
border: true,
region: 'center',
store: storecl,
title: 'Client',
columns: [
// new Ext.grid.RowNumberer(),
{text: 'ID',dataIndex: 'id'},
{ text: 'type',align: 'center',dataIndex: 'type'},
{ text: 'nom',align: 'center',dataIndex: 'nom'},
{ text: 'Prénom',align: 'center',dataIndex: 'prenom'},
{ text: 'Matricule',align: 'center',dataIndex: 'mat'}
],
listeners: {itemdblclick: function(grid ,record){
var rr = grid.getSelectionModel();
var rs = rr.getSelection();
var idc = rs[0].get('id');
Ext.Ajax.request({
url: 'PHP/op.php',
params: {
idcl: idc
}
});
storeop.load({params:{idcl: idc}});
}}
},{
xtype: 'grid',
flex: 1,
region: 'south',
border: true,
store: storeop,
title: 'Liste des opportunités',
columns: [
// new Ext.grid.RowNumberer(),
{text: 'ID',dataIndex: 'id'},
{ text: 'Date',align: 'center',dataIndex: 'date'},
{ text: 'Info',align: 'center',dataIndex: 'infos'},
{ text: 'Produit',align: 'center',dataIndex: 'idProd'},
{ text: 'CLient',align: 'center',dataIndex: 'idcl'}
]
}
]
})
}
return win;
}
});
I want the second grid to dsiplay the records loaded from the store storeop with parameters selected from the first grid. Any help?
you can get the selected row from the first grid:
var selectedRecord = firstGrid.getSelectionModel().getSelection()[0];
here, i assume that you have a single selection model. To load this selectedRecord to your second grid, you have to loadData to its store.
list.push(selectedRecord.data);
secondGrid.store.loadData(list, false);
take note that you have to use different store for each grid.
You need a second Store instance for your second grid. Do not use the same store for both grids.

Resources