Как установить данные строк таблицы данных за пределами первой страницы с помощью сценария Java? - PullRequest
0 голосов
/ 11 февраля 2019

Ниже моя ajax-функция для изменения значений строки с первой страницы и отображения итоговых значений другой страницы таблицы данных.

            $.ajax({
                    type : "Post",
                    contentType : "application/json; charset=UTF-8",
                    url : 'editPYActual.do',
                    cache : false,
                    data : JSON.stringify(array),
                    success : function(result) {

                    //document.getElementById("finTotal").innerText = 
                      result.employee.finTotal;


              $('#tList1').dataTable().fnUpdate(result.employee.finTotal , 
              $('tr#lastRow')[12], 8 );
         });

и ниже мой HTML-код tr, значение которого должно отражаться:

           <tr>
              <td id="finTotal">2251</td>`enter code here`
           <tr>

1 Ответ

0 голосов
/ 13 февраля 2019
I have solved this by using footer of datatable for performing sum of column of datatable

below is my jsp code:

<tfoot>

   <tr>

      <th colspan="8" style="text-align:right">Total:</th>


     <td id="finTotal">${employee.finTotal}</td>

     <td id="sumMonth1">${employee.sumMonth1}</td>

     <td id="sumMonth2">${employee.sumMonth2}</td>

     <td id="sumMonth3">${employee.sumMonth3}</td>

     <td id="sumMonth4">${employee.sumMonth4}</td>

     <td id="sumMonth5">${employee.sumMonth5}</td>

     <td id="sumMonth6">${employee.sumMonth6}</td>

     <td id="sumMonth7">${employee.sumMonth7}</td>

     <td id="sumMonth8">${employee.sumMonth8}</td>

     <td id="sumMonth9">${employee.sumMonth9}</td>

     <td id="sumMonth10">${employee.sumMonth10}</td>

     <td id="sumMonth11">${employee.sumMonth11}</td>

     <td id="sumMonth12">${employee.sumMonth12}</td>

 </tr>  

And following is js code:


$('#tList1').dataTable({

        "columnDefs": [
            {"targets": 3,"width": "80px"},
            {"targets": 4,"width": "100px"}
        ],
        dom : 'lBfrtip',
        buttons : [
        /* 'excel', */
        {
            extend : 'excel',
            text : 'Export File',
            exportOptions : {
                modifier : {
                    selected : null
                }
            }
        }

        ],
        select : null,
        "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;

            // Remove the formatting to get integer data for summation
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };

            // Total over all pages
            total = api
                .column( 8, { search: 'applied'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

            // Update footer
            $( api.column( 8 ).footer() ).html(
                 total 
            );
        }

    });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...