Templates define the way data is rendered inside of List. You can define multiple templates and switch between them dynamically.
myList = new dhtmlXList({
container:"data_container",
type:{
template:"#Package# : #Version#<br/>#Maintainer#",
height:40
}
});
The { Package:"a", Version:"b", Maintainer:"c"} will be rendered as:
a : b <br/> c
A template can be defined as a part of the constructor (or not) as:
myList.define("type",{
template:"#Package# : #Version#<br/>#Maintainer#"
});
If you need to provide only a text string and don't need any extra properties, you can use the "template" property directly on the top level (i.e. don't use the type parameter):
myList = new dhtmlXList({
container:"data_container",
template:"#Package# : #Version#<br/>#Maintainer#"
});
myList.define("type",{
template:"#Package# : #Version#<br/>#Maintainer#"
});
Related sample: Template from JS string
myList.define("type",{
template:function(){ return obj.Package +"<br/>"+obj.Maintainer; }
});
Related sample: Template from JS function
<textarea id="template_container" rows="5" cols="60">
#Package# : #Version#
<br/>#Maintainer#</textarea>
...
myList.define("type",{
template:"html->template_container",
})
Related sample: Template from HTML container
myList.define("type",{
template:"http->../common/template.html",
})
Related sample: Template from HTML file
dhtmlx.Type.add(dhtmlXList,{
name:"dataA",
template:"#Package# : #Version#<br/>#Maintainer#",
height:40
});
data = new dhtmlXList({
container:"data_container",
type:"dataA"
});
Related sample: Named templates
"#property#" - replaced with a value of the related property
myList.define("type",{
template:"#a# - #b#"
})
// a - b
"{common.property}" - replaced with a constant value from the template
myList.define("type",{
template:"#a# - {common.mydata}",
mydata:25
})
// a - 25
"{common.method()}" - replaced with the result of a method call
myList.define("type",{
template:"#a# - {common.mymethod()}",
mymethod:function(obj){
return obj.b.toUpperCase();
}
})
// a - B
"#property?valueA:valueB#" - trinary operator
myList.define("type",{
template:"#a# - #flag?exist:not exist#"
})
// a - doesn't exist
"{-obj" - replaced with #
Sometimes it can be useful to change some parameter of a template. As a result, the view will be repainted with a new configuration.
myList.customize({
height:100
});
If you define some property in template as {common.some}, you will be able to change it any time by using the "customize" command.
myList = new dhtmlXList({
container:"data_container",
type:{
template:"#Package# : #Version#<br/>#Maintainer#",
css:"some",
width:120,
height:40,
margin:5,
padding:0,
}
});
If you want apply a custom css style to the template, use the following technique:
myList = new dhtmlXList({
container:"data_container",
type:{
template:"#Package# : #Version#<br/>#Maintainer#",
css:"custom",
}
});
.dhx_list_custom_item_selected{
font-weight:bold !important;
}
.dhx_list_custom_item{
font-size:12px !important;
}
Note, the css property has the default value - 'default'. So, you can skip step 1 and define the css classes with the following names:
In addition to a standard template, List can have an additional task-specific template defined:
myList = new dhtmlXList({
container:"data_container",
edit:true,
type:{
template:"#Package# : #Version#<br/>#Maintainer#",
template_edit:"<input class='dhx_item_editor' bind='obj.Package'>"
}
});
Back to top