Pregunta

I puede generar tabla de datos durante formulario de inicialización. (JSF). Entonces quiero Javascript para escribir los datos leídos de ricos: los valores dataTable

<f:view>
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

      <script type="text/javascript">
            function getTableValue()
            {
                //Here i want to write code for get one by one value  
                //from rich:datatable content
            }
      </script>

    </head>
    <body>
      <h:form id="tableForm" binding="#{DataTable.initForm}">

        <rich:dataTable id="salesTable" value="#{DataTable.saleList}" var="data">
          <f:facet name="header">
            <rich:columnGroup>
              <rich:column>
                <h:outputText value="Sales" />
              </rich:column>
            </rich:columnGroup>
          </f:facet>
          <rich:column>
            <h:outputText value="#{data.salesPercentage}" />
          </rich:column>
        </rich:dataTable>

        <input id="tableButton" type="button" value="getDataTableValue" onclick="getTableValue()" />

      </h:form>
    </body>
  </html>
</f:view>

Ayuda mí. Gracias por su esfuerzo.

¿Fue útil?

Solución

En primer lugar obtener la tabla del documento (página rightclick, do Ver código para ver id generada a sí mismo).

var table = document.getElementById('tableForm:salesTable');

A continuación, obtener las filas como un array desde el cuerpo de la tabla.

var rows = table.getElementsByTagName("tbody")[0].getElementsByTagName("tr");

bucle Luego sobre las filas y obtener las células como matriz a partir de la fila.

for (var i = 0; i < rows.length; i++) {
    var cells = rows[i].getElementsByTagName("td");
}

bucle continuación sobre las células y obtener el contenido.

for (var j = 0; j < cells.length; j++) {
    var cell = .cells[j];
    alert(cell.innerHTML);
}

Ver también:

Otros consejos

function processDelete()
{
   var table = document.getElementById('AluminumPricingTab:forecastYearList');     var rows = table.getElementsByTagName("tbody")[0].getElementsByTagName("tr"); var yearAdd = "";
    for (var i = 0; i < rows.length; i++) {
        //alert("rows:" + i);       var cells = rows[i].getElementsByTagName("td");     var checked = document.getElementById("AluminumPricingTab:forecastYearList:"+i+":deleteSelectedRowCHK").checked;
        //alert("checked:" +checked); 
        if (checked)
        {              
             if(yearAdd != "")
                {
                yearAdd = yearAdd + ',' ;
                }
            else
                {
                  yearAdd;
                }
            var year = document.getElementById("AluminumPricingTab:forecastYearList:"+i+":year").value; 
            yearAdd = yearAdd + year;

            //alert("yearAdd:" +yearAdd);  
        }       
    }
     if (yearAdd != "")
         {
            var result = confirm(MSG_FORECASTS_DELETE_SELECTED +'\n\n'+ yearAdd);
            if (result == true)
            {   
                //alert("Row deleted"); 
                var bt1 = document.getElementById('AluminumPricingTab:deleteSelectedForecast');
                bt1.onclick='document.body.style.cursor = "wait";return true;';
                bt1.click();
            }   
            else 
            {
                return false;   
            }
         }
     else
         {
           alert("Select Row to deleted"); 
         }
  }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top