I try to binding data from window grid that show by trigger field click.
this is my form with triggerfield :
Ext.define('ResApp.view.group.Detail', {
extend: 'Ext.window.Window',
alias:'widget.groupdetail',
floating: true,
hidden: false,
width: 450,
//height: 400,
resizeable: false,
title: 'Detail Group',
modal: true,
initComponent: function() {
var me = this;
Ext.applyIf(me, {
....other config...
items: [
{
xtype: 'form',
itemId: 'groupDetailForm',
border: false,
layout: {
type: 'auto'
},
bodyPadding: 10,
preventHeader: true,
title: 'My Form',
items: [
....other items...
{
xtype: 'triggerfield',
padding: '0 0 5 0',
width: 350,
fieldLabel: 'Nama Kontak',
name: 'namaJamaah',
itemId: 'namaLead',
triggerCls: ' x-form-search-trigger',
onTriggerClick: function(){
Ext.widget('listjamaahgroup').show();
}
},
....other items...
]
}
]
});
me.callParent(arguments);
}});
next, my window with grid to list data :
Ext.define('ResApp.view.group.ListJamaahGroup', {
extend: 'Ext.window.Window',
alias:'widget.listjamaahgroup',
height: 400,
width: 750,
title: 'Daftar Jamaah',
modal: true,
hidden: false,
floating: true,
resizeable: false,
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items : [
{
xtype: 'gridpanel',
autoScroll: true,
border:false,
title: 'Daftar Anggota',
itemId: 'gridAnggota',
preventHeader: true,
forceFit: true,
flex: 1,
store: 'Jamaah',
allowDeselect : true,
viewConfig: {
autoScroll: true
},
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
cls:'border-bottom',
items: [
{
xtype: 'button',
text: 'Pilih',
iconCls:'edit',
action: 'selectJamaahGrp',
itemId: 'selectJamaahGrp'
},
{
xtype: 'button',
text: 'Baru',
iconCls:'add'
}
]
}
],
columns: [
....Grid columns...
]
}
]
});
me.callParent(arguments);
}});
and this is my controller :
Ext.define('ResApp.controller.GroupDetails', {
extend: 'Ext.app.Controller',
stores: [
'Group', 'Jamaah'
],
models: [
'Group', 'Jamaah'
],
views:[
'group.Detail',
'group.ListJamaahGroup'
],
init: function(){
this.control({
...
'button[action=selectJamaahGrp]': {
click: this.selectJamaahGrp
},
...
});
},
... other functions ...
selectJamaahGrp: function(button, e, options) {
//windowDetail.hide();
var grid = button.up('grid');
if (grid) {
var windowDetail = Ext.widget('groupdetail');
var form = windowDetail.down('form');
var sm = grid.getSelectionModel();
var rs = sm.getSelection();
if (!rs.length) {
Ext.Msg.alert('Info', 'Pilih salah satu');
return;
}
var data = grid.getSelectionModel().getSelection()[0];
//how to setValue to triggerfield from here
}
button.up('listjamaahgroup').destroy();
},
batalSelClick: function(button, e, options) {
button.up('listjamaahgroup').destroy();
}
... other functions ...})
my problem is, i can't figure how to setValue the triggerfield from my controller. Or there's another way to do it?
Just define a ref in your controller (refs: [ { ref: 'trigger', selector: 'triggerfield' } ]) and then perform this.getTrigger().setValue().
Related
In Extension grid paging and filtering is not working..please help me out.In this code if i replace store with simplestore and ds.load() with ds.loadData(mydata) then simple grid is working but paging is not working.but i have seen some samples according to these i have converted my code..but after that its not working at all.
Ext.onReady(function () {
var myData = [
['Apple', 29.89, 0.24, 0.81, '9/1 12:00am'],
['Ext', 83.81, 0.28, 0.34, '9/12 12:00am'],
['Google', 71.72, 0.02, 0.03, '10/1 12:00am'],
['Microsoft', 52.55, 0.01, 0.02, '7/4 12:00am'],
['Yahoo!', 29.01, 0.42, 1.47, '5/22 12:00am']
];
var ds = new Ext.data.Store({
pageSize: 2,
proxy: {
type: 'pagingmemory',
reader: { type: 'array' }
},
fields: [
{ name: 'company' },
{ name: 'price', type: 'float' },
{ name: 'change', type: 'float' },
{ name: 'pctChange', type: 'float' },
{ name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia' }
]
});
var colModel = new Ext.grid.ColumnModel([
{ header: "Company", width: 120, sortable: true, dataIndex: 'company' },
{ header: "Price", width: 90, sortable: true, dataIndex: 'price' },
{ header: "Change", width: 90, sortable: true, dataIndex: 'change' },
{ header: "% Change", width: 90, sortable: true, dataIndex: 'pctChange' },
{ header: "Last Updated", width: 120, sortable: true,
renderer: Ext.util.Format.dateRenderer('m/d/Y'),
dataIndex: 'lastChange'
}
]);
var grid = new Ext.grid.GridPanel({ frame: true, height: 200, width: 600,ds: ds, cm: colModel, bbar: new Ext.PagingToolbar({
store: ds,
pageSize: 2,
displayInfo: true
})
});
ds.load();
grid.render(Ext.getBody());
});
I am working with the mvc nested-loading example: http://docs.sencha.com/ext-js/4-1/#!/example/app/nested-loading/nested-loading.html. While trying to build my own project out of this I ran in to a problem trying to render the data in my content view. For some reason the templated data is not loading. I have a feeling it's something to do with xtype: 'component'. I changed it to panel and I seen the border but still no data. I also included the app.jsb3 file and that does not work either. I can see the data listed in the bind method but gets added.
My json data:
[
{id: 1, name: 'This is page one', url: 'http://my.test.com/test.html'},
{id: 2, name: 'This is page two', url: 'http://my.test.com/test2.html'}
]
My Model:
Ext.define('TST.model.Projects', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'url']
});
My Store:
Ext.define('TST.store.Projects', {
extend: 'Ext.data.Store',
model: 'RLA.model.Projects',
autoLoad: true,
proxy: {
type: 'ajax',
url : 'resources/json/projects.json'
}
});
My Controller:
Ext.define('TST.controller.Menu', {
extend: 'Ext.app.Controller',
stores: ['Projects'],
models: ['Projects'],
refs: [
{ref: 'mainLeftMenu', selector: 'mainleftmenu'},
{ref: 'mainContent', selector: 'maincontent'}
],
init: function() {
this.control({
'mainleftmenu': { selectionchange: this.onLeftMenuChange },
});
this.getProjectsStore().on({
scope: this,
load : this.onProjectsStoreLoad
});
},
onProjectsStoreLoad: function(store, records) {
Ext.defer(function() {
if (records.length) {
var record = records[0];
this.getMainLeftMenu().getSelectionModel().select(record);
console.log("iamhere");
}
}, 500, this);
},
/* load the project menu items */
onLaunch: function() {
this.getMainLeftMenu().bindStore(this.getProjectsStore());
},
/* update content on new selection */
onLeftMenuChange: function (view, records) {
if (records.length) {
this.showContent(records[0]);
}
},
showContent: function(record) {
this.getMainContent().bind(record);
}
});
Here is my leftContent view:
Ext.define('TST.view.main.LeftMenu', {
extend: 'Ext.view.View',
alias: 'widget.mainleftmenu',
initComponent: function() {
Ext.apply(this, {
id: 'leftmenu',
dock: 'left',
width: 200,
border: true,
cls: 'leftMenu',
selModel: {
deselectOnContainerClick: false
},
itemSelector: '.items',
tpl: [
'<div class="menuTitle">Projects</div>',
'<tpl for=".">',
'<div class="items">{name}</div>',
'</tpl>'
]
});
this.callParent(arguments);
}
});
Here is my content view:
Ext.define('TST.view.main.Content', {
extend: 'Ext.panel.Panel',
alias: 'widget.maincontent',
initComponent: function() {
Ext.apply(this, {
cls: 'content',
flex: 2,
border: false,
autoScroll: true,
layout: {
type: 'hbox',
align: 'middle',
pack: 'center',
availableSpaceOffset: Ext.getScrollbarSize().width
},
items: [
{
xtype: 'component', // think it has something to do with this?
itemId: 'contentCt',
width: 500,
height: 200,
border: 2,
tpl: [
'<div class="url">{url}</div>'
]
}]
});
this.callParent(arguments);
},
bind: function(record) {
this.child('#contentCt').update(record.getData());
}
});
And firebug shows that record.getData() returns:
object { id=1, name="This is page one", url="http://my.test.com/test.html"}
You will need to post more code, since this works without issue:
Ext.define('TST.view.main.Content', {
extend: 'Ext.panel.Panel',
alias: 'widget.maincontent',
initComponent: function() {
Ext.apply(this, {
cls: 'content',
flex: 2,
border: false,
autoScroll: true,
layout: {
type: 'hbox',
align: 'middle',
pack: 'center',
availableSpaceOffset: Ext.getScrollbarSize().width
},
items: [{
xtype: 'component', // think it has something to do with this?
itemId: 'contentCt',
width: 500,
height: 200,
border: 2,
tpl: ['<div class="url">{url}</div>']
}]
});
this.callParent(arguments);
},
bind: function(data) {
this.child('#contentCt').update(data);
}
});
Ext.onReady(function(){
var p = new TST.view.main.Content({
width: 500,
height: 200,
renderTo: document.body
});
p.bind({
url: 'foo'
});
});
I'm trying to create a Sencha Touch 2 form panel for a model in which one of the fields contains the URL to an image file. If I include a textfield, it'll display the text of the URL correctly, but what I really want is to display the image found at that URL, and I'm not sure how to do that. If I use xtype: image, I think I need a src config, and I'm not sure how to specify that the desired value is in one of the form fields. My view looks like this:
Ext.define("CatalogApp.view.ItemDetailView", {
extend: "Ext.form.Panel",
requires: "Ext.form.FieldSet",
alias: "widget.itemdetailview",
config:{
scrollable:'vertical'
},
initialize: function ()
{
this.callParent(arguments);
var backButton = {
xtype: "button",
ui: "back",
text: "Home",
handler: this.onBackButtonTap,
scope: this
};
var topToolbar = {
xtype: "toolbar",
docked: "top",
title: "Item Detail",
items: [
backButton
]
};
var mainLayout = {
xtype: "container",
layout: 'hbox',
items: [
{
xtype: 'textfield',
width: 200,
name: 'thumbUrl'
},
{
xtype: "fieldset",
flex: 1,
items : [
{
xtype: 'textfield',
name: 'itemNbr',
label: 'Item Nbr',
disabled: true
},
{
xtype: 'textfield',
name: 'itemDesc',
label: 'Item Desc',
disabled: true
}
]
}
]
};
this.add([
topToolbar,
mainLayout
]);
},
onBackButtonTap: function ()
{
console.log("backToHomeCommand");
this.fireEvent("backToHomeCommand", this);
}
});
How can I set up this view to display the image correctly?
You have to define new Sencha component: ImageField
Ext.define('Ext.ux.field.ImageField', {
extend: 'Ext.field.Field',
requires: [
'Ext.Img'
],
xtype: 'imagefield',
config: {
component: {
xtype: 'image'
}
},
updateValue: function(value, oldValue) {
var me = this,
component = me.getComponent();
component.setSrc(value);
},
proxyConfig: {
width: '100%',
height: '100%'
}
});
Than in form:
Ext.define("CatalogApp.view.ItemDetailView", {
extend: "Ext.form.Panel",
requires: "Ext.form.FieldSet",
alias: "widget.itemdetailview",
config:{
scrollable:'vertical'
},
initialize: function ()
{
this.callParent(arguments);
var backButton = {
xtype: "button",
ui: "back",
text: "Home",
handler: this.onBackButtonTap,
scope: this
};
var topToolbar = {
xtype: "toolbar",
docked: "top",
title: "Item Detail",
items: [
backButton
]
};
var mainLayout = {
xtype: "container",
layout: 'hbox',
items: [
{
xtype: 'imagefield', // only this change
width: 200,
height: 150,
name: 'thumbUrl'
},
{
xtype: "fieldset",
flex: 1,
items : [
{
xtype: 'textfield',
name: 'itemNbr',
label: 'Item Nbr',
disabled: true
},
{
xtype: 'textfield',
name: 'itemDesc',
label: 'Item Desc',
disabled: true
}
]
}
]
};
this.add([
topToolbar,
mainLayout
]);
},
onBackButtonTap: function ()
{
console.log("backToHomeCommand");
this.fireEvent("backToHomeCommand", this);
}
});
Cheers, Oleg
My grid is not filled, though the store is filled with json data. What is wrong?
I want all data from "csv":[...] to be written to the grid columns.
If I console.log() the store, my json data is located at store.proxy.reader.[jsonData|rawData].data.csv => Array[4]
Json Data:
{"status":{"status":0,"msg":"Ok","protocolversion":"1.1.json"},"data":{"headline":{"headline":"headline"},"csv":[{"key":"0","value":"...lugin\/monitor\/files\/logfilefilter_worker_error.log"},{"key":"1","value":"...les\/logfilefilter-worker01-progress.log.1331769600"},{"key":"2","value":"...\/application\/x\/plugin\/monitor\/files\/Test.log"},{"key":"3","value":"...ind\/plugin\/monitor\/files\/logfile_for_navi_test.log"}]}}
Model:
Ext.define( 'Monitor.model.ComboLogfiles', {
extend: 'Ext.data.Model',
fields: [ {name: 'key'}, {name: 'value'} ]
} );
Store:
Ext.define( 'Monitor.store.ComboLogfiles', {
extend : 'Ext.data.Store',
model : 'Monitor.model.ComboLogfiles',
proxy : {
type : 'ajax',
url : '/devel/phi/dev/04-presentation/http-api/index.php',
extraParams: {
user : 'test',
pass : 'test',
vers : '1.1.json',
module : 'monitor',
func : 'getLogfiles'
},
reader : {
type: 'json',
root: 'csv'
// root: 'data'
}
},
autoLoad: true
} );
Controller
var store = Ext.create('Monitor.store.ComboLogfiles');
oLogfileSelector = Ext.create("Ext.window.Window", {
title: 'Logfiles',
width: '200',
height: '400',
autoScroll: true,
flex: 1,
minimizable: false,
maximizable: false,
style: 'background-color: #fff;',
items: [{
xtype: 'panel',
items: [
Ext.create('Ext.grid.Panel', {
id: 'mygrid',
store: store,
width: 200,
height: 200,
title: 'Logfiles',
columns: [
{
text: 'Key',
width: 50,
sortable: false,
dataIndex: 'key'
}
,{
text: 'File',
width: 100,
sortable: false,
dataIndex: 'value'
}
]
})
]
}]
}).show();
Maybe try like this:
reader: {
type: 'json',
root: 'data.csv',
successProperty:false
}
I need to display a checkbox for column "Active" and when I change the selection to be to able to make an ajax request, to update the database.
Some sample code will help me a lot.
Thanks.
Please check this link: Extjs Grid plugins.
You can check sources for second grid.
Also you need listen 'selectionchange' event for selection model of the grid - so you'll have selected rows and then you can submit a request to server or whatever you need.
If you need specific column (not the first one) - you can check this link: Checkbox in the grid
And I think this is same here too: how to add checkbox column to Extjs Grid
This is example from one of my projects:
Ext.define('Magellano.view.news.List' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.newslist',
store: 'News',
remoteSort: false,
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Online',
id: 'online-button',
enableToggle: true,
icon: '/images/light-bulb.png',
pressed: true,
handler: onItemToggle
}, { text: 'Preview',
id: 'preview-button',
enableToggle: true,
pressed: true
}],
initComponent: function() {
this.selModel = Ext.create('Ext.selection.CheckboxModel', {
singleSelect: false,
sortable: false,
checkOnly: true
});
this.columns = [
{ text: '', width: 28, renderer: function(val) { return "<img src='/images/star-empty.png' height='16' width='16'></img>"}},
{ text: 'Date', width: 60, dataIndex: 'newstime', renderer: renderDate},
{ text: 'Agency', width: 60, dataIndex: 'agency', renderer: function(val) { return val;}},
{ text: 'Category', width: 60, dataIndex: 'category', renderer: function(val) { return val;}},
{ text: 'Title', flex: 1, dataIndex: 'title',
renderer: function(val) { return Ext.String.format('<b>{0}</b>', val); }
}
];
this.title = "News from " + Ext.Date.dateFormat(new Date(), "j M Y");
this.callParent(arguments);
}
}
The important part is that in the initComponent you create the selection model:
this.selModel = Ext.create('Ext.selection.CheckboxModel', {
singleSelect: false,
sortable: false,
checkOnly: true
});