pagination on extjs where using a data store - extjs

I am having issue setting up pagination.
using the following example.
http://docs.sencha.com/ext-js/4-0/#/guide/application_architecture
I have create a store in a separate file.
ie /app/store/tasks.js
app/store/tasks.js
Ext.define('AM.store.Tasks', {
extend: 'Ext.data.Store',
model: 'AM.model.Task',
autoLoad: true,
pageSize: 2,
proxy: {
type: 'ajax',
api: {
read: '/WarehouseProductImport/IndexGrid',
update: 'data/updateTasks.json'
},
reader: {
type: 'json',
root: 'tasks',
totalProperty: 'total',
successProperty: 'success'
}
}
});
in my app.js
launch: function () {
Ext.create('Ext.container.Container', {
width: 950,
height: 500,
renderTo: 'panelcontainer',
items: [
{
xtype: 'tasklist',
title: 'Tasks',
html: 'List of tasks will go here'
}
],
dockedItems: [{
xtype: 'pagingtoolbar',
store: '', // how do i get this store as it's define in 'store/task.js'
dock: 'bottom',
displayInfo: true
}]
});
}
In the above method, "store" isn't initialized. Am i putting this method in the correct place. Are there any examples on how to set up pagination when the store is separated like above.

Related

ExtJS Loading Link List Tree Using Ajax

I have the below code that I am trying to get the list of dates using Ajax and display those on the page as links to elsewhere. So each entry would be a link that when you click would take you elsewhere. Though the treelist is not loading any items...
Data
{
"success": true,
"data": [
"2018-10-08T00:00:00",
"2018-10-05T00:00:00",
"2018-10-04T00:00:00",
"2018-10-03T00:00:00",
]
}
Code
Ext.define('...', {
extend: 'Ext.form.Panel',
xtype: '...',
requires: [
'...'
],
layout: 'border',
items: [{
xtype: 'container',
store: {
proxy: {
type: 'ajax',
url: '...',
useDefaultXhrHeader: true,
withCredentials: true,
reader: {
type: 'json',
rootProperty: 'data'
},
}
}
}]
});
You can display a grid with your data. It can show clickable links.
To do this you need to make a grid with your ajax store and a grid renderer like this:
// Ajax store
Ext.create('Ext.data.Store', {
storeId: 'mystore',
autoLoad: true,
proxy: {
type : 'ajax',
url : '/file.php',
actionMethods: {
read: 'POST'
},
reader : {
type: 'json'
},
extraParams : {
key : 'val'
},
fields : [
{name: 'date', type: 'string'}
]
}
})
// Grid
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
scrollable: true,
store: {
type: 'mystore'
},
columns: [
{
text: 'link column',
dataIndex:'link',
renderer: function(value) {
if(value) {
// here you can format your output
return ''+value+'';
}
}
}
]
})
Please look whole example in a Fiddle

Combobox list is transparant after populate

I try to use a combobox in my formpanel. This works and the store is loading when you click on the combobox. But when it is loaded it is not showing a background.I try to build and refresh the app but no matter what i do or what theme i use it keeps showing it transparant.
This is my combobox
{
xtype: 'combobox',
name: 'type',
anchor: '100%',
fieldLabel: 'Type',
displayField:'naam',
valueField:'id',
multiSelect: false,
editable: false,
store: 'ProductenGroepComboTypeJsonStore',
listConfig: {
loadingText: null,
loadMask: false
}
}
the store is this
Ext.define('JustRent.store.ProductenGroepComboTypeJsonStore', {
extend: 'Ext.data.Store',
requires: [
'JustRent.model.ProductenGroepComboTypeModel',
'Ext.data.proxy.Ajax',
'Ext.data.reader.Json'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'ProductenGroepComboTypeJsonStore',
model: 'JustRent.model.ProductenGroepComboTypeModel',
proxy: {
type: 'ajax',
url: 'resources/json/productType.php',
reader: {
type: 'json',
rootProperty: 'data'
}
}
}, cfg)]);
}
});
this is how it looks like
I'm not sure if this is ideal for you but you can define the css classes to apply to your list and try to do a workaround that way
listConfig: {
xtype: 'boundlist',
baseCls: 'your-css-list',
maxHeight: 200,
itemCls: 'your-css-list-item'
}
Hope it helps :)

sencha touch 2 how create url dynamic store from item list

I need to pass the value of selected item in the list to a list of detail to load data from a store.
The code view is
Ext.define('App.view.PresidentList', {
extend: 'Ext.List',
xtype: 'presidentlist',
requires: ['App.store.Presidents','Ext.dataview.NestedList','Ext.data.proxy.JsonP'],
config: {
title: 'Events',
iconCls: 'star',
//grouped: true,
itemTpl: '<b>{evento}</b><br>{nombre}',
store: 'Presidents',
onItemDisclosure: true,
}
});
The code controller is
Ext.define('App.controller.Main', {
extend: 'Ext.app.Controller',
config: {
refs: {
main: 'mainpanel'
},
control: {
'presidentlist': {
disclose: 'showDetail'
}
}
},
showDetail: function(list, record) {
var listItems = Ext.create('App.store.ListItems', {newUrl : record.getData()});
listItems.load();
this.getMain().push({
xtype: 'presidentdetail',
title: record.fullName(),
data: record.getData(),
store: listItems
});
}
});
the code view datail is
Ext.define('App.view.PresidentDetail', {
extend: 'Ext.tab.Panel',
xtype: 'presidentdetail',
config: {
title: 'Details',
scrollable: 'vertical',
items:
[
{
extend: 'Ext.List',
xtype: 'presidentlist',
requires: ['App.store.ListItems','Ext.dataview.NestedList','Ext.data.proxy.JsonP'],
config: {
title: 'Events',
iconCls: 'star',
//grouped: true,
itemTpl: '<b>{evento}</b><br>{nombre}',
store: 'ListItems',
onItemDisclosure: true,
}
},
{
xtype: 'nestedlist',
title: 'Contactos',
id: 'panel2',
useToolbar:false,
displayField: 'title',
store: {
type: 'tree',
fields: [
'title','link','author','contentSnippet','content',
{name: 'leaf', defaultValue: true}
],
root: {
leaf: false
},
proxy: {
type: 'jsonp',
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog/',
reader: {
type: 'json',
rootProperty: 'responseData.feed.entries'
}
}
},
detailCard: {
xtype: 'panel',
scrollable: true,
styleHtmlContent: true
},
listeners: {
itemtap: function(nestedList, list, index, element, post) {
this.getDetailCard().setHtml(post.get('content'));
}
}
},
{
xtype: 'panel',
id: 'panel5',
title: 'Costos',
iconCls: 'home'
},
{
xtype: 'panel',
title: 'Otros',
iconCls: 'favorites',
id: 'panel5'
},
]
}
});
and the code store of ListItems is
Ext.define('App.store.ListItems',{
extend: 'Ext.data.Store',
autoLoad: true,
config: {
model: 'App.model.President',
proxy: {
//autoLoad: true,
type: 'ajax',
url:<-------->here comes the url with the variable that is passed from the list
reader: {
type: 'json',
rootProperty: "test"
}
}
}
});
Please collaboration with this issue not to do this. thank you very much.
If you just want to change the url of the proxy on a store, you can do like this
Ext.getStore('YourStoreId').getProxy().setUrl("your_new_url");
Ext.getStore('YourStoreId').load();
You must use estraParams inside the proxy
extraParams:{Parm1:2, Parm2:'eeee'},

Sencha Touch, one store to be used by a list and a dataview display?

So I implemented a dataview and a list format card to display my json in store. I am trying to get the two view to share one store, since the data are the same. However the way i am doing it is not really working, if I only have Dataview or List it works fine. When I have both call the store, it will stop working... please help!
Dataview:
Ext.define('Sencha.view.hoardboard.HoardList', {
extend: 'Ext.DataView',
xtype: "hoardlist",
requires: ['Ext.XTemplate'],
config: {
flex:1,
scrollable: true,
store: 'Plist',
baseCls: 'columns',
itemTpl: '<div class=pin><img src={image}><div style="padding-top: 10px; padding-left: 20px; padding-right:20px">{name}<br>{brand}</div></div>'
}
});
List view
Ext.define('Sencha.view.hoardboard.HoardList2', {
extend: 'Ext.List',
xtype: "hoardlist2",
config: {
flex:1,
scrollable: true,
store: 'Plist',
grouped: true,
itemTpl: '{name}'
}
});
Model
Ext.define('Sencha.model.HoardList', {
extend: 'Ext.data.Model',
config: {
fields: [
{
name: 'name',
type: 'string'
},
{
name: 'image',
type: 'string'
},
{
name: 'type',
type: 'string'
},
{
name: 'brand',
type: 'string'
}
,
{
name: 'color',
type: 'string'
},
{
name: 'description',
type: 'string'
}
]
}
});
Store
Ext.define('Sencha.store.HoardList',{
extend: 'Ext.data.Store',
storeId: 'Plist',
model:'Sencha.model.HoardList',
title: 'My Collection',
autoLoad: true,
sorters: 'name',
grouper: {
groupFn: function(record) {
return record.get('name')[0];
}
},
proxy: {
type: 'ajax',
url : 'products.json',
reader: {type: 'json', rootProperty:'products'}
}
});
Thank you so much!
Generally speaking when you're using Sencha framework you don't share one store object between several visual controls.
If you want to use same store in two places you need to clone it and have two separate store objects.

EXTJS MVC Tree store

Am having a tree view which gets its data from the tree store. But, however, am able to see only the small folders that gets displayed as part of a tree structure. the name of the nodes is not getting displayed, and when i try to print the record, it just says that its an empty string. Here is the code:
App/View
Ext.define('App.view.Hierarchy', {
alias: 'widget.hierarchy',
extend: 'Ext.panel.Panel',
initComponent: function () {
var config = {
xtype: 'panel',
border: false,
autoScroll: true,
baseCls: 'topMenu',
html: '<div class="PageTitle" style="width:600px;"><b>' + LANG.HIERARCHYT + '</b><br>' + LANG.HIERARCHYTxt + '<br>' + '</div>',
items: [{
xtype: 'toolbar',
border: false,
dock: 'top',
items: [{
xtype: 'button',
text: LANG.BTADDREG,
iconCls: 'icon-add-tb',
cls: 'tip-btn',
iconAlign: 'right',
action: 'addRegion',
id: 'ADDREGION'
}]
},
{
xtype: 'treepanel',
title: 'Hierarchy Tree',
id: 'hierarchyTree',
border: false,
alias: 'widget.hierarchyTree',
height: 1000,
viewConfig: {
enableDD: true,
plugins: {
ptype: 'treeviewdragdrop'
}
},
collapsible: false,
useArrows: true,
rootVisible: false,
store: Ext.create('Campus.store.HierarchyTree'),
displayField: 'Title',
multiSelect: false,
singleExpand: false,
}]
}
var holder = Ext.getCmp('center');
holder.remove(0);
holder.add(Ext.apply(config));
this.callParent(arguments);
}
});
Model
Ext.define('App.model.HierarchyTree', {
extend : 'Ext.data.Model',
fields : ['Title', 'ID', 'LevelID', 'ParentID']
});
Store
Ext.define('App.store.HierarchyTree', {
extend: 'Ext.data.TreeStore',
model: 'App.model.HierarchyTree',
storeID: 'HierarchyTree',
proxy: {
type: 'ajax',
url: 'data/Locations.aspx',
reader: {
},
actionMethods: {
create: 'POST',
read: 'POST',
update: 'POST'
},
extraParams: {
mode: 'HIERARCHYFULLLIST'
}
},
autoLoad: true
});
Controller
Ext.define('App.controller.Hierarchy', {
extend: 'Ext.app.Controller',
stores: ['Me', 'Regions', 'Areas', 'Towns', 'HierarchyTree'],
model: ['Me', 'Teams', 'Regions', 'User', 'HierarchyTree'],
views: ['App.view.Hierarchy', 'App.view.AddRegions'],
refs: [{
ref: 'myHierarchyTree',
selector: 'hierarchyTree'
}],
init: function () {
this.getHierarchyTreeStore().load();
this.control({
'button[action=addRegion]': {
click: this.addRegion
},
'#hierarchyTree': {
itemclick: this.itemclick
}
})
},
itemclick: function (view, record) {
console.log(record.get('Title'))
}
});
Also, the JSON thats being returned is:
{"text":".","children": [{"text":"Asia Pacific","id":"537","level":"1", "expanded":
false,"singleClickExpand":true,"children":[{"text":"Japan", "cls":"xtreenode-Level2-
Indent", "id":"538", "hl1":"537","level":"2","singleClickExpand":true, "expanded":
false, "children":[]},
Treepanel's display field defaults to text, which is ok with the json being returned, but the problem is the store model, which should include as fields the text, cls ..and other attributes you have in your json. Otherwise these will not be mapped to the records and you get empty text.
Ext.define('App.model.HierarchyTree', {
extend : 'Ext.data.Model',
fields : ['Title', 'ID', 'LevelID', 'ParentID', 'text', 'level','cls,....]
EDIT
You have modified the displayField to be the Title, but the json doesn't contain the title attribute. You have to simple fixes, either you modify the model if the text is actually the title. You can do this by setting a mapping to the field.
Ext.define('App.model.HierarchyTree', {
extend : 'Ext.data.Model',
fields : [{name:'Title',type:'string',mapping:'text'}, 'ID', 'LevelID', 'ParentID',]
This will cause the Title to be populated by the text values from the json.
Also you can remove the displayField config and then the text value will be applied, but this will still mean that the 'Title' value will be empty.
OK, finally got it:)
Set the displayfield in the tree to 'text'
displayfield : 'text'
And, Once again thank you nscrob
And one more question, could you please give me any guidance on how to open different views depending upon the level in the tree that is being clicked
This works.
if (record.get('level')==1)
{
this.erWin = Ext.create('App.view.EditRegions');
this.erWin.showWin();
}
else{
//open another_view
}

Resources