I want to add images in front of the text in an ExtJS combobox. I have the following code in listConfig...
listConfig: {
getInnerTpl: function(displayField) {
var tpl = '<div>' +'my img path is here' + '{name}</div>';
return tpl;
}
},
And my store is like this
Ext.define('state', {
extend: 'Ext.data.Model',
fields: [{ name: 'stateCode', type: 'int' }, { name: 'name', type: "string"}]
});
My JSON response from the server...
[{"stateCode":"0","name":"--Select--"},{"stateCode":"1","name":"ABC"},{"stateCode":"2","name":"XYZ"},{"stateCode":"3","name":"OPQ"},{"stateCode":"188587","name":"LMN"}]
Here i get the image infront of all items in combobox, but I only want the image infront of items with stateCode 1.
Please help
listConfig: {
getInnerTpl: function(displayField) {
var tpl = new XTemplate(
'<div>',
'<tpl if="stateCode > 0">',
'<img src='img/path/image.jpg' />',
'</tpl>',
'</div>'
);
return tpl;
}
}
I know this is old, but since I've encountered similar problem just recently, I'm gonna post my solution, maybe it will be some help to others.
In this case, you can do something like this:
listConfig: {
getInnerTpl: function(displayField) {
var tpl = '<div>' +'{[values.stateCode == 0 ? "<img src=\'path/to/image.jpg\'" : ""]}' + '{name}</div>';
return tpl;
}
},
var tpl = '<div><img src='img/path/image.jpg' class="state-{state}" />{name}</div>';
then uses css clasess to do something with your image (like hide or show)
I'm using ExtJS 5 and this is working for me:
listConfig: {
itemTpl: [
'<tpl if="stateCode = 0"', // If you have to use '<' or '>' you have to encode it (>)
'<img src="path/to/img.png" /> {name}',
'<tpl else>',
'{name}',
'</tpl>'
]
}
None of the answers so far were working for me, except #riza, but that doesn't provide enough logic for what I needed to do with multiple else if statements. It turns out that others were using "," instead of "+" (except #riza) to concatenate the strings of the tpl. Also, #MMZurita makes a good point with the encoding special characters in HTML. So > becomes > and < becomes <. The <div> and </div> need to go at the beginning and end of the actual tpl tag!
listConfig: {
getInnerTpl: function() {
var tpl =
'<div>' +
'<tpl if="id == 1">' +
'<img src="resources/icons/one.png" align="left"> {name}' +
'<tpl elseif="id == 2">' +
'<img src="resources/icons/two.png" align="left"> {name}' +
'<tpl elseif="id > 2">' +
'<img src="resources/icons/Custom.png" align="left"> {name}' +
'<tpl else>' +
'<img src="resources/icons/Standard.png" align="left"> {name}' +
'</tpl>' +
'</div>';
//);
return tpl;
}
}
Related
I have the following structure of my grid
$scope.grid = $("#prospectsGrid").kendoGrid({
columns: [
{ template: "<input type='checkbox' class='checkbox' />", width: "3%" },
{ template: "#= FirstName + ' ' + LastName #", title: "Name" },
{ field: "FirstName", hidden: true },
{
command: [
{
name: "edit",
text: "<span class='glyphicon glyphicon-pencil' aria-hidden='true'></span>"
}
}).data("kendoGrid");
As you can see I am accessing this grid with the help of an identifier that is #prospectsGrid. Now without changing any of the functionality inside the grid, I need to replace the identifier (#prospectsGrid) with some angular element. How can I do that? Any help would be appreciated.
Just for reference my HTML Code is
<div id="prospectsGrid" class="gridcommon"></div>
As micjamking says in comments, you need inject in your module KendoUI directives.
angular.module("myApp",["kendo.directives"])
Then you will can use in your html code something like this
<div kendo-grid="myKendoGrid"
k-options="myKendoGridOptions">
</div>
In controller:
angular.module("managerOMKendo").controller("myController", function ($scope) {
// Functions controller
$scope.createMyGrid = function () {
$scope.myKendoGridOptions = {
columns: [ {
field: "FirstName",
template: "<input type='checkbox' class='checkbox' />", width: "3%"
},
command: [{
name: "edit",
text: "<span class='glyphicon glyphicon-pencil' aria-hidden='true'></span>"
}]
// Here you can put your complete configuration. Check official example
}
}
}
// Main thread
$scope.createMyGrid(); // call the function that creates the grid
});
Here is the official example
It´s possible that you need change something. For example where I have written text, maybe you have to write template. It´s hard without plunker.
Good luck!
I have an ExtJS 4.2 view.View (dataView) using a template, store and model; pretty much as the documentation describes, and the information is displayed fine.
I now need to alternate the background colour of each item. How is this best accomplished?
There aren't any easy config options to do this like Sencha Touch's striped: true, or any inherent styling like in the grid.Panel; I have looked for a listener that would allow for setting the tpl and itemSelector for each item, but there doesn't seem to be anything listed that would suffice.
Code:
Ext.define('productionHistoryModel', {
extend: 'Ext.data.Model',
fields: [ 'Date', 'Fore_Name', 'Event', 'Comments' ]
});
var productionHistoryStore = Ext.create('Ext.data.Store', {
id: 'productionHistoryStore',
storeId: 'productionHistoryStore',
model: 'productionHistoryModel'
});
var historyTpl1 = new Ext.XTemplate(
'<tpl for=".">',
'<div style="margin-bottom: 10px;" class="x-grid-row">',
'<span style="font-weight: bold;">{Date}: {Event} ({Fore_Name})</span>',
'<br/><span>{Comments}</span>',
'</div>',
'</tpl>'
);
var productionHistoryView = Ext.create('Ext.view.View', {
id: 'productionHistoryView',
store: productionHistoryStore,
tpl: historyTpl1,
itemSelector: 'div.x-grid-row',
emptyText: 'No logs available',
disableSelection: true,
autoScroll: true,
maxHeight: 500
});
You're using a view which means you're defining the HTML to be generated yourself, using a XTemplate. That is why there is no built-in feature for striped rows, since the framework simply doesn't know which HTML will be rendered.
The simplest solution is to add a class attribute to each row in your template indicating whether the row number is odd or even, and then use CSS to style the rows accordingly.
Actually there already is an example in the documentation of Ext.XTemplate (scroll down to "Execute arbitrary inline code with special built-in template variables"):
var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>',
'<p>Company: {[values.company.toUpperCase() + ", " + values.title]}</p>',
'<p>Kids: ',
'<tpl for="kids">',
'<div class="{[xindex % 2 === 0 ? "even" : "odd"]}">',
'{name}',
'</div>',
'</tpl></p>'
);
The corresponding CSS code would look like:
.odd {
background-color: white;
}
.even {
background-color: gray;
}
I am new to Snecha so please bear my non technical description.
MyView.js
itemTpl: [
'<div class="pb10 font-90">{associationDiplayText}</div>' +
'<div style="float:left">' +
'<div class="bold font-90"><b>{name}</b></div>' +
'<div class="font-90">{address1}</div>' +
'<div class="font-90">{address2}</div>' +
'</div>' +
'<div style="display:block;" class="fltR" id="displayIcon">' +
'<span id="phoneId" class="phoneIcon"></span>' +
'<span id="emailId" class="emailIcon"></span>' +
'<div class="clr"></div>' +
'</div>' +
'<div class="clr"></div>' +
'<div style="display:none" id="display" class="mt15 mb10">'+
'<tpl for="contacts">',
'<div style="float:left">' +
'<div class="font-50">{contactTypeText}:</div>' +
'<div class="font-50">{name}</div>' +
'</div>' +
'<div class="fltR" id="innerdisplay">' +
'<span id="contactphone" class="phoneIcon"></span>' +
'<span id="contactemail" class="emailIcon"></span>' +
'<input type="hidden" value="{#}" id="hiddenindex" />'+
'<div class="clr"></div>' +
'</div>'+
'<div class="clr"></div>' +
'</tpl>',
'</div>'+
'<div align="center">{moreDetail}</div>'
]
Controller.js In onItemTap I am doing following
onItemTapListView: function(view, itemIndex, target, record, event, eOptions) {
if(event.getTarget("#contactphone.phoneIcon")){
var contactRecord = record.data.contacts[itemIndex];
}
The problem is that when i click the first row it gives itemIndex = 0 which is what I expect but it also gives the same result when I click on phoneIcon from contact list which has around 10,15 items. what I need is to get the index on which contact item user has clicked.
Thanks in Anticipation
Each instance of the 1st-level record object will be set to a different row no mather what it contains.
ST wont ever know on which contact is the user tapping because the entire row is a single unit.
I know the UI would be different, but my recommendation is to go with a Nested List approach.
regards-
I'm trying to retrieve images from database to data view using ExtJS 4. Now I need to pass parameters dynamically. Mostly here..........
Ext.define('${pkgName}.v02x003001.SV02X00300102' , {
extend : 'Ext.view.View',
alias : 'widget.sv02x00300102',
id : 'images-view',
autoScroll : true,
trackOver : true,
multiSelect : true,
height : 310,
overItemCls : 'x-item-over',
itemSelector : 'div.thumb-wrap',
emptyText : 'No images to display',
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;
},
initComponent: function() {
var me = this;
var value= Ext.getCmp('member-sv02x00300104').getValue();
me.store = 'S02X003001',
me.tpl = [
'<tpl for=".">',
'<div class="thumb-wrap" id="{name}">',
'<div class="thumb"><img src="${createLink(mapping:'img', params:[member: **value** , width:100, height:100])}" title="{name}"></div>',
'<span class="x-editable">{shortName}</span></div>',
'</tpl>',
'<div class="x-clear"></div>'
];
me.callParent(arguments);
}
});
So my question is how do I set value into params ( for member field )
createLink is a grails component that is processes server side, before your JS code is run.
You can't pass JS variables to a Java component because Java will always be processed first on the server and then the resulting HTML and JS will be sent to the client for processing. Client will know nothing about your server side code blocks.
I suggest you rewrite createLink piece in HTML and substitute in JS variables like you do with name and short name.
I would like to add a custom value to each item of a Ext.view.View, this is a window name that should be opened when the item will be clicked.
I'm reading the API docs and I found only how to set custom function, is a problem if I set a custom attribute too?
Thanks for any suggestion
What I'm reading: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.XTemplate
Edit 1:
Ext.define('MyApp.view.desktop.Icons', {
extend: 'Ext.view.View',
alias : 'widget.iconsdataview',
tpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'<div class="mfo-view">',
'<img src="{image}" alt="{image}" />',
'<p>{title}</p>',
'</div>',
'</tpl>'
),
itemSelector: 'div.mfo-view',
store: 'Icons',
style: 'margin: 2em;',
overItemCls: 'mfo-view-over',
trackOver: true
});
I would like to do something like this:
tpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'<div class="mfo-view">',
'<img src="{image}" alt="{image}" />',
'<p>{title}</p>',
'</div>',
'</tpl>',
mycustomproperty: '{property}'
),
and then on itemdblclick event (pseudocode)
itemdblclick(obj, ...) {
openMyWindow(obj.mycustomproperty);
}
Hope this helps
I haven't worked to much in EXTJS 4.o mostly 3.3 but I believe you can do the following:
tpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'<div class="mfo-view">',
'<img src="{image}" alt="{image}" />',
'<p>{title}</p>',
'</div>',
'</tpl>',
{ mycustomproperty: '{property}'
}
),
Seems like what I want is not possible because object created by template are htmlelement, and you have to do Ext.get to make them Elements, to actually use them as ExtJS objects.
I solved by accessing the store with the index of itemdblclick method.
Edit 1:
Even better, you can access the item with record parameter, without using index.