Problem on iterate through listgrid

I have problem on iterate through listgrid.

In Listgrid i have to display Checkbox and Country Name, when user click on button i need to get what are checkboxes are selected. Please help me on this

My code as below

<e:variable name="mydata" type="application/xml">
<e:data type="text/xml">
<ItemsInfo>
    <Item>
       <KeyValue>IND</KeyValue>
       <Name>India</Name>
    </Item>
    <Item>
       <KeyValue>AUS</KeyValue>
       <Name>Australia</Name>
    </Item>
    <Item>
       <KeyValue>ENG</KeyValue>
       <Name>England</Name>
    </Item>
    <Item>
       <KeyValue>NZL</KeyValue>
       <Name>New Zeland</Name>
    </Item>
    <Item>
       <KeyValue>PAK</KeyValue>
       <Name>Pakistan</Name>
    </Item>
    <Item>
       <KeyValue>BAN</KeyValue>
       <Name>Bangladesh</Name>
    </Item>
    <Item>
       <KeyValue>KEN</KeyValue>
       <Name>Kenya</Name>
    </Item>
     <Item>
       <KeyValue>SFA</KeyValue>
       <Name>South Africa</Name>
    </Item>
</ItemsInfo>
</e:data>
</e:variable>

<b:dataSource name="myData" e:behavior="b:localData" dataType="application/xml" dataSelect="$mydata">
  <b:dataFormatter name="myCheckStyle" type="application/javascript">
  <![CDATA[
   return "<input type='checkbox' id='" + value + "' value='" + value + "' onclick='fnCheckRow(this);' />";
  ]]></b:dataFormatter>
</b:dataSource>

<b:listGrid id="myGrid" showColumnHeaders="false" dataSource="myData" readonly="true">
   <b:listGridCol query="KeyValue" width="30px" format="myCheckStyle" />
   <b:listGridCol query="Name"  width="130px" />
</b:listGrid>

<b:button id="enabledSubmit">
<e:handler event="click" type="text/javascript">
try
{
  var oListGrid = bb.document.getElementById('myGrid');
  var testRecords=oListGrid.viewNode.selectSingelNode("./div/table/tbody/tr");
  alert(testRecords.length);
}
catch(e)
{
  alert(e.message);
}
</e:handler>
Click Me
</b:button>

I got output as zero, I also tried with oListGrid.selectSingelNode("./div/table/tbody/tr"), its also given me the zero.

I also tried with var totalRecords=oListGrid.getProperty('localRecords') to get the total records but when check the Length of "totalRecords" i am getting "undefined" message.

thanks in advance

Problem on iterate through listgrid

Hi,

I don't know why you put try and catch there but if you remove those try and catch , you should be able to get total record. If you want to get what input has been checked and total checked input, you can have a look the following example. First, I get all records using selectNodes then I select the one is checked (by inputs[i].checked==true) and look the check input's id (inputs[i].id) or count them (by count++).

<b:button id="enabledSubmit">
        <e:handler event="click" type="text/javascript"><![CDATA[
                var listGrid = bb.document.getElementById('myGrid');   
                var inputs = listGrid.viewNode.selectNodes("./div/table/tbody/tr/td[1]/div/input");
                var count = 0;
                for(var i=0;i<inputs.length;i++){
                        if(inputs[i].checked==true){
                                       console.info(inputs[i].id);
                                        count++;
                       }
                }
              console.info(count);
        ]]></e:handler>
Click Me
</b:button>

Cheers,
Yudi

Re: Problem on iterate through listgrid

Hi,

Thanks for your reply.

When i try to execute above i am getting "object doesn't support this property or method" for "listGrid.viewNode.selectNodes"

Please help me on this.

listgrid iterate

Hi rnalamati,

The code that Yudi made is actually work for FF2. But it indeed does not work in the IE. ( I tried it with IE7).
It is because the listgrid.viewNode does not have the "selectNodes" method. Therefore, it will always return error.

You can try this code below:

var inputs = listGrid.selectNodes("view()/div[3]/table/tbody/tr/td[1]/div/input");

It works for both FF2 and IE7

hope this helps

Andys