Checkbox unchecked after item onSelectChange event

I have a dataview that uses the following dataview:

[code] var dvThumb = thumbPanel.attachDataView({
type: {
template: “

#ord#
”,
template_loading: “Loading…”
}
});

// this allows the checkbox to be selected directly without first selecting the image/item.
dvThumb.attachEvent("onItemClick", function (id, ev, trg) {
    if ((ev.target || ev.srcElement).tagName == "INPUT") {
        return false;
    }
});[/code]

The checkbox is unchecked after the “item” / image is selected or unselected. It appears to happen when the onSelectChange event is fired. Is there a way to maintain the state of the checkbox after onSelectChange fires?

Hello,

the item is recreated when you select it. For this reason, checkbox state should be considered in item data and template.

here is a small sample:

dvThumb = thumbPanel.attachDataView({ type: { template: "<input type='checkbox' class='my_checkbox' {obj.checked?checked:} ' onclick=''>" } });

You need to set “checked” for item when checkbox is clicked. It can be done by on_click collection. There you can set the event handler for html element of an item by its className. In my example it is ‘my_checkbox’ (see the template above):

data.on_click.my_checkbox = function(e){ var itemId = this.locate(e); this.get(itemId).checked = (e.target||e.srcElement).checked }

Method locate gets item id by event object.

Hi,
you have answered like below

data.on_click.my_checkbox = function(e){
var itemId = this.locate(e);
this.get(itemId).checked = (e.target||e.srcElement).checked
}

here data represents what?

Please provide more detailed explanation about checkbox issue in dataview.

I too have the same issue with check box – onselection of item checkbox get unchecked

Thanks,

Naresh Adla

here data represents what?

Dataview

In the above example it would be more correct to use dvThumb instead of data:

dvThumb.on_click.my_checkbox = function(e){

}