4

I have a table which has checkbox for each row. I am unable to select multiple checkboxes simantaneously. Below is the code of Item Tpl for ref:

+'<tpl for="rows">'
 + '<tr>'
   +'<tpl for="columns">'
     +'<tpl if="dataIndex== \'checkbox\'">'
        + '<td><input type="checkbox" id="checkbox{#}" class="regular-checkbox" /><label class="m0" for="checkbox{#}"></label></td>'
    +'<tpl else>'
      +'<td><p>{value}</p></td>'
    +'</tpl>'
  +'</tpl>'
 +'</tr>'
+'</tpl>'

I have a problem to get index for the rows loop in item Tpl to have a unique id for each checkbox. Can anyone guide me hoe to get it ?

1 Answers1

6

Ext.XTemplate has support for verbatim blocks (syntax {% ... %}). Any code contained in these blocks will be inserted directly in the generated code for the template.

So in parent loop you can declare your own local variable where you store current index {% var parentIndex = xindex; %}. Then in child loop you can get value of this variable by {[parentIndex]}

Your complete template code should be:

'<tpl for="rows">'
 +'{% var parentIndex = xindex; %}'
 + '<tr>'
   +'<tpl for="columns">'
     +'<tpl if="dataIndex== \'checkbox\'">'
        + '<td><input type="checkbox" id="checkbox{[parentIndex]}" class="regular-checkbox" /><label class="m0" for="checkbox{[parentIndex]}"></label></td>'
    +'<tpl else>'
      +'<td><p>{value}</p></td>'
    +'</tpl>'
  +'</tpl>'
 +'</tr>'
+'</tpl>'
Akatum
  • 3,976
  • 2
  • 18
  • 25