lpkf
#1
Hello all,
Is there any way to disable some itens of dataview to avoid user select them?
On attached picture, you can see left dataview with some itens grayed. That is what I mean.
If does not have a simple way, do you have any tip?
Best regards,
Luis
Darya
#2
Hello
There is no approach to disable an item. You can design it as disabled and prevent selection via onClick event handler
lpkf
#3
Hello Darya,
Thanks for your answer.
I did it in a little bit different way:
- On object, add a property to test if item will be enabled or not;
<data>
<item id='1'>
<name>foo</name>
<disabled>0</disabled>
</item>
<item id='2'>
<name>bar</name>
<disabled>1</disabled>
</item>
<item id='3'>
<name>foobar</name>
<disabled>0</disabled>
</item>
</data>
- On dataview template: test property and adjust correct style if necessary to show item as disabled.
template: function(obj) {
return '<div style="text-align: center;'+(parseInt(obj.disabled) == 1 ? 'opacity:0.4; filter:alpha(opacity=40)' : '')+'">'+obj.name+'</div>';
}
- Using event onBeforeSelect, test object property created on item 1.
objDataView.attachEvent('onBeforeSelect', function(id, state) {
return (parseInt(objDataView.get(id).disabled) == 0);
});
That’s it.
Best regards,
Luis
Darya
#4
Hello Luis,
Great solution. Thanks for sharing it!