Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  169] [ 4]  / answers: 1 / hits: 24193  / 14 Years ago, tue, february 15, 2011, 12:00:00

I am trying to develop a FilterEditor using ExtJS.
user creates some range, comparison, null/notnull criterias and I need to present them in a well-formatted format, so that users can read the overall criteria easily.



For this, I tought Ext.DataView and XTemplates would do the trick. But I am wondering if I can provide more than one template to makes templates maintainable, or use some built-in functionality to select a piece of the template for me.



   var dateRangeTpl = new Ext.XTemplate(
'<tpl for=.>',
'<div id={CriteriaId}>',
'<em>{FieldName} </em>',
'<span>{Modifier} </span>',
'<span>{Condition} </span>',
'<span>{LeftDate} </span>',
'<span>{RightDate} </span>',
'</div>',
'</tpl>',
'<div class=x-clear></div>'

var notNullTpl = new Ext.XTemplate(
'<tpl for=.>',
'<div id={CriteriaId}>',
'<em>{FieldName} </em>',
'<span>{Modifier} </span>',
'<span>{Condition} </span>',
'</div>',
'</tpl>',
'<div class=x-clear></div>'


output:



Invoice Date not between 2011-01-01 2011-01-31
Invoice Date not null


There will be a lot of templates, I am thinking of providing some inline data editors, so most probably this will grow in numbers. I know I can do some simple blocks it might grow big and complicated so I wanted some opinions before I dive into it.


More From » extjs

 Answers
3

I think the most powerful aspect of templates are template member functions that you can call within your template. With these the possibilities are endless. For example you can use them to render other subtemplates within your main template:



var mainTpl = new Ext.XTemplate(
'<tpl for=.>',
'<div class=container>',
'{[this.renderItem(values)]}',
'</div>',
'</tpl>',
{
renderItem: function(values) {
if (values instanceof DateRange) {
return dateRangeTpl.apply(values);
}
else {
return notNullTpl.apply(values);
}
}
}
);


For a great overview of templates check out Sencha conference video: Advanced Templates for Ext JS.


[#93726] Sunday, February 13, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckenna

Total Points: 445
Total Questions: 109
Total Answers: 109

Location: Virgin Islands (U.S.)
Member since Sun, May 16, 2021
3 Years ago
;