I have a backend, which returns a JSON, I load that into a store, it loads fine, then call a refresh on the view from the controller, and I always get the emptyText value of the view, template is not refeshing.
EDIT: It is working now! The below setup if functioning, the problem was how I used to lookup the view.
Controller:
showNotes: function(activityId) {
var me = this;
Ext.Ajax.request({
url: MyApp.Config.BASE_URL + '/someURL',
method: 'GET',
success: me.successGetNotes.bind(me),
failure: me.failureGetNotes
});
},
successGetNotes: function(result) {
var notesStore = this.getNotesStore(), //This gets me the store ok
publishersStore = this.getPublishersStore(),
data = Ext.JSON.decode(result.responseText);
notesStore.loadRawData(data.result.notes);
publishersStore.loadRawData(data.result.publishers);
this.getNotesPanel().refresh(); //this calls the refresh on the DataView ok
//TODO
},
Model:
Ext.define('MyApp.model.Note', {
extend: 'Ext.data.Model',
fields: [
'publisherId',
'text' ,
{
name: 'created',
type: 'date',
dateFormat: 'c'
}
]
});
Store:
Ext.define('MyApp.store.Notes', {
extend: 'Ext.data.Store',
model: 'MyApp.model.Note',
alias: 'store.Notes',
storeId: 'Notes'
});
main view:
...
items: [
{
xtype: 'notes-panel',
//store: Ext.data.StoreManager.lookup('Notes'), NO!!!
store: 'Notes', //YES!
flex: 1
}
]
...
notes-panel:
Ext.define('MyApp.view.sections.notes.NotesPanel' ,{
extend: 'Ext.DataView',
alias: 'widget.notes-panel',
//deferInitialRefresh: false,
itemSelector: 'div.something',
tpl: new Ext.XTemplate(
// '<tpl for=".">',
// '<div class="something">',
// '<p>ID:{publisherId}</p>',
// '<p>{text}</p>',
// '<p>{created}</p>',
// '</div>'
// '</tpl>',
'<table width="100%" border="0">',
'<tpl for=".">',
'<div class = "something">',
'<tr><td width="85">ID:</td><td width="315">{publisherId}</td></tr>',
'<tr><td>Note:</td><td>{text}</td></tr>',
'</div>',
'</tpl>',
'<table>'
),
emptyText: 'No data available'
})
;
Example response:
{
"success": true,
"result": {
"publishers": [
{
"id": "009999",
"type": "xy",
"isReceipient": false,
"description": "xy"
},
{
"id": 45,
"type": "xy",
"isReceipient": true,
"description": "xy"
},
{
"id": 45,
"type": "xy",
"isReceipient": false,
"description": ""
}
],
"notes": [
{
"publisherId": "009999",
"text": "xy",
"created": "2014-02-23T18:24:06.074Z"
},
{
"publisherId": "45",
"text": "xy",
"created": "2014-02-23T18:24:06.074Z"
},
{
"publisherId": 45,
"text": "xy",
"created": "2014-02-23T18:24:06.074Z"
}
]
}
}
And another thing: I would also like to use publisherId in notes to print the publisher name and type, so I will need two store's data. I was thinking of loading the other store by lookup in the DataView, and getting the publisher that way. Is that feasible?
from Ext.DataView.itemSelector:
A simple CSS selector (e.g. div.some-class or span:first-child) that will be used to determine what nodes this DataView will be working with. The itemSelector is used to map DOM nodes to records. As such, there should only be one root level element that matches the selector for each record.
and like you can the in the example from DataView:
var imageTpl = new Ext.XTemplate(
'<tpl for=".">',
'<div style="margin-bottom: 10px;" class="thumb-wrap">',
'<img src="{src}" />',
'<br/><span>{caption}</span>',
'</div>',
'</tpl>'
);
the class is under the tpl element, so I think in your example you need to create a div under the tpl node.
Related
I have problem with dataview store filter.
In tpl i have created the member function called 'isHeader' for grouping the header, If i'm having the multiple records under the same title. By default it is working good.
But when I'm searching the 'columnName', the header function called twice. So it always return false.
If the header function called once, it will return true. that time only i'm able to show header.
and please refer the JSON data and store & model.
{
"mainsummary": [
{
"Analysisoption": "Hosts Under Maintenance",
"columnName": "java"
},
{
"Analysisoption": "Hosts Under Maintenance",
"columnName": "DC1"
},
{
"Analysisoption": "Component Tests Maintenance",
"columnName": "Java Classes",
"hostName": "java:13600"
}
]
}
I have declared the variable as global
var titleObj = new Object();
{
xtype:'panel',
tools:[
{
xtype: 'trigger',
enableKeyEvents :true,
scope: this,
listeners : {
specialkey: function(field, e){
if (e.getKey() == e.ENTER) {
srch = field.getValue();
var dataViewObj = Ext.getCmp('dataviewObj');
store = dataViewObj.getStore();
store.filterBy(function(record, id){
host = record.get('columnName');
pattern = new RegExp(srch, 'gi');
if((pattern.test(host))){
titleObj = new Object();
return true;
}
});
store.sort(); //important to maintain proper sort order in the list
Ext.getCmp('dataviewObj').refresh();
}
},
}
}
],
items: [{
xtype: 'dataview',
id:'dataviewObj',
store: new Ext.data.Store({
fields: [
{name: 'columnName', type: 'string'},
{name: 'hostName', type: 'string'},
{name: 'Analysisoption', type: 'string'}
],
data:mainsummary
}),
tpl: new Ext.XTemplate([
'<tpl for=".">',
'{% var parentIndex = xindex; %}',
'<div class="maintenanceTable" style="margin:10px !important">',
'<tpl if="!Ext.isEmpty(Analysisoption) && this.isHeader(Analysisoption)">',
'<div>{Analysisoption} </div>',
'</tpl>',
'<table id="tableId" border="0" align="center" width="100%">',
'<tbody>',
'<tr>',
'<td><div>{columnName}</div></td>',
'<tpl if="!Ext.isEmpty(hostName)">',
'<td>{hostName}</td>',
'</tpl>',
'</tr>',
'</tbody>',
'</table>',
'</div>',
'</tpl>',
{
isHeader:function(Analysisoption){
console.log("isHeader",Analysisoption);
var isPrintHeader = false;
if(titleObj!=null && !titleObj.hasOwnProperty(Analysisoption))
{
titleObj[Analysisoption]=true;
isPrintHeader=true;
}
return isPrintHeader;
}
}
])
}]
}
i am trying to have a combobox in Extjs such that user should not edit the default value which is already available :
Here is the code i tried:::
Ext.onReady(function () {
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data: [{
"abbr": "AL",
"name": "Alabama"
}, {
"abbr": "AK",
"name": "Alaska"
}, {
"abbr": "AZ",
"name": "Arizona"
}]
});
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
editable:false,
queryMode: 'local',
valueField: 'abbr',
renderTo: Ext.getBody(),
// Template for the dropdown menu.
// Note the use of "x-boundlist-item" class,
// this is required to make the items selectable.
tpl: Ext.create('Ext.XTemplate', '<tpl for=".">', '<div class="x-boundlist-item">{abbr} - {name}</div>', '</tpl>'),
// template for the content inside text field
displayTpl: Ext.create('Ext.XTemplate', '<tpl for=".">', '{abbr} - {name}', '</tpl>')
});
});
Although i do editable:false ... but it didnt work.
Please help.
Due to some cache problem , editable:false was not working
however it is correct solution
I have an extjs dataview:
var dv = Ext.create('Ext.view.View', {
store: this.eventInstanceImagesStore,
tpl: [
'<tpl for=".">',
'<div class="thumb-wrap" id="{name:stripTags}">',
'<div class="thumb"><img src="http://stimages.blob.core.windows.net/medium/{value}" title="{name:htmlEncode}"></div>',
'<span class="x-editable">{shortName:htmlEncode}</span>',
'</div>',
'</tpl>',
'<div class="x-clear"></div>'
],
multiSelect: true,
trackOver: true,
overItemCls: 'x-item-over',
itemSelector: 'div.thumb-wrap',
emptyText: 'No images to display',
plugins: [
// Ext.create('Ext.ux.DataView.DragSelector', {}),
Ext.create('Ext.ux.DataView.LabelEditor', { dataIndex: 'name' })
],
prepareData: function (data) {
Ext.apply(data, {
shortName: Ext.util.Format.ellipsis(data.name, 15),
sizeString: Ext.util.Format.fileSize(data.size),
dateString: Ext.util.Format.date(data.lastmod, "m/d/Y g:i a")
});
return data;
}
});
I also have a file upload form which, when the image has been successfully uploaded I am reloading the dataview:
dv.store.reload({
params: {
id: eid
}
});
However, when the reload happens it seems to re-add the images twice. So I end up with 2 dataviews... Has anyone seen this before?
Try doing dv.store.removeAll(); first before doing a
dv.store.reload({
params: {
id: eid
}
});
I try to define a dataview from http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.view.View to http://jsfiddle.net/JtTDH/
Here is my code
Ext.define('Example', {
extend: 'Ext.view.View',
tpl: new Ext.XTemplate(
'<tpl for=".">',
'<div style="margin-bottom: 10px;" class="thumb-wrap">',
'<img src="{src}" />',
'<br/><span>{caption}</span>',
'</div>',
'</tpl>'
),
itemSelector: 'div.thumb-wrap',
emptyText: 'No images available',
initComponent: function() {
var store = Ext.create('Ext.data.Store', {
id:'imagesStore',
fields: [
{ name:'src', type:'string' },
{ name:'caption', type:'string' }
],
data: [
{ src:'http://www.sencha.com/img/20110215-feat-drawing.png', caption:'Drawing & Charts' },
{ src:'http://www.sencha.com/img/20110215-feat-data.png', caption:'Advanced Data' },
{ src:'http://www.sencha.com/img/20110215-feat-html5.png', caption:'Overhauled Theme' },
{ src:'http://www.sencha.com/img/20110215-feat-perf.png', caption:'Performance Tuned' }
]
});
this.store = store;
this.callParent(arguments);
}
});
I think that's correct but that's not working. How to fix that thank.
Your code is fine, but you need to define a rendering target for it. For example, you could add renderTo: Ext.getBody() to your definition, and it will work correctly. See a working example here: https://fiddle.sencha.com/#fiddle/md
I have been getting UnCaught SyntaxError : Unexpected Token : .
I'm really puzzled where this would come from. When i use the sample json it works
http://www.sencha.com/forum/topics-browse-remote.php
The issue maybe that i should use httpProxy. But i'm unsure how to incorporate this.
Ext.Loader.setConfig({ enabled: true });
Ext.Loader.setPath('Ext.ux', '../ux/');
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.toolbar.Paging',
'Ext.ux.PreviewPlugin',
'Ext.ModelManager',
'Ext.tip.QuickTipManager'
]);
Ext.onReady(function () {
Ext.tip.QuickTipManager.init();
Ext.define('ForumThread', {
extend: 'Ext.data.Model',
fields: [
'title', 'threadid'
],
idProperty: 'threadid'
});
// create the Data Store
var store = Ext.create('Ext.data.Store', {
pageSize: 50,
model: 'ForumThread',
remoteSort: true,
proxy: {
type: 'jsonp',
//url: 'http://www.sencha.com/forum/topics-browse-remote.php',
url: 'https://www.estore.localhost/usergrid/indexgrid',
reader: {
root: 'topics',
totalProperty: 'totalCount'
},
// sends single sort as multi parameter
simpleSortMode: true
},
sorters: [{
property: 'title',
direction: 'DESC'
}]
});
// pluggable renders
function renderTopic(value, p, record) {
return "test";
}
var pluginExpanded = true;
var grid = Ext.create('Ext.grid.Panel', {
width: 700,
height: 500,
title: 'ExtJS.com - Browse Forums',
store: store,
disableSelection: true,
loadMask: true,
viewConfig: {
id: 'gv',
trackOver: false,
stripeRows: false,
plugins: [{
ptype: 'preview',
bodyField: 'excerpt',
expanded: true,
pluginId: 'preview'
}]
},
// grid columns
columns: [{
// id assigned so we can apply custom css (e.g. .x-grid-cell-topic b { color:#333 })
// TODO: This poses an issue in subclasses of Grid now because Headers are now Components
// therefore the id will be registered in the ComponentManager and conflict. Need a way to
// add additional CSS classes to the rendered cells.
id: 'topic',
text: "Topic",
dataIndex: 'title',
flex: 1,
renderer: renderTopic,
sortable: false
}],
// paging bar on the bottom
bbar: Ext.create('Ext.PagingToolbar', {
store: 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);
}
}]
}),
renderTo: 'topic-grid'
});
// trigger the data store load
store.loadPage(1);
});
Here is the json
{
"totalCount": "4",
"topics": [{
"threadid": "435",
"title": "55e38867-2b1e-4fc4-8179-5907c1c80136"
}, {
"threadid": "444",
"title": "4975db6c-d9cd-4628-a6e9-ca1d4815d28d"
}, {
"threadid": "529",
"title": "c778e5ea-eb79-42b1-8f13-7cba4600491f"
}, {
"threadid": "530",
"title": "a1024264-9eed-4784-ab91-cf2169151478"
}]
}
jsonP is a special technique for retrieving data from a server in a different domain. The main idea of jsonP is that
JsonPProxy injects a <script> tag into the DOM whenever an AJAX
request would usually be made
So imagine what would happen if proxy processed your json. It would inject <script> tag like this:
<sript>
{
"totalCount": "4",
"topics": [{
"threadid": "435",
"title": "55e38867-2b1e-4fc4-8179-5907c1c80136"
},
// ...
]
}
</script>
When this script is being executed it defenetly throws an exception.
So, like Xupypr MV has already written, you should wrap your outcoming-from-server string into:
myCallback(
//your json here
);
in this case JsonPProxy would inject <script> like this:
<sript>
myCallback({
"totalCount": "4",
"topics": [{
"threadid": "435",
"title": "55e38867-2b1e-4fc4-8179-5907c1c80136"
},
// ...
]
});
</script>
and it would be valid <script> tag.
Now you have to indicate in the store that you are using 'myCallback' as callback function (notice the callbackKey config):
var store = Ext.create('Ext.data.Store', {
// ...
proxy: {
type: 'jsonp',
url: 'https://www.estore.localhost/usergrid/indexgrid',
callbackKey: 'myCallback',
// ...
},
// ...
});
Check out docs for more info.
Notice, original (sencha example) url returns some extra data, not only json.
Make you response look like this:
Ext.data.JsonP.callback1({
"totalCount": "4",
"topics": [{
"threadid": "435",
"title": "55e38867-2b1e-4fc4-8179-5907c1c80136"
}, {
"threadid": "444",
"title": "4975db6c-d9cd-4628-a6e9-ca1d4815d28d"
}, {
"threadid": "529",
"title": "c778e5ea-eb79-42b1-8f13-7cba4600491f"
}, {
"threadid": "530",
"title": "a1024264-9eed-4784-ab91-cf2169151478"
}]
});
I was having the same problem and took me a while to figure it out.
I'm using Sencha Touch 2, which also implements the Ext.data.proxy.JsonP. The Extjs 4 proxy automatically creates a callback parameter each time it is sent to the server, e.g. callback1, callback2, sequentially. It is important to catch this parameter and return it with the json, otherwise the second time it is called it will complain not having a callback1 method.
The section "Implement on the server side" on this page
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.proxy.JsonP
describes how to create callback with the JsonP. I suppose the original example http://www.sencha.com/forum/topics-browse-remote.php also does this.
I was also having the same problem, and was a mistake in server side code. I was using php file but not appended the callback going from frontend. So http://docs.sencha.com/touch/2-0/#!/api/Ext.data.proxy.JsonP is helpful which explains the structure of different types of serverside code for jsonp request
Thanks
Tapaswini