cannot read row values on client side when using Editor

cannot read row values on client side when using Editor

Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0

I included some columns on client side using render for example

{ data: null,
render: function (data, type, row)
{
// var numFormat = $.fn.dataTable.render.number( ",", ".", 0 ).display;
}},

and it works fine but when I try to read the values of all rows using :
var data = tablecontracts
.rows()
.data()
it only shows the those columns which are read from server side and doesn't show the columns with NULL values.

How can I read all the data into an array for all columns including the NULL one?

Please
Thank you

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    The cell().render() or cells().render() are used for getting the rendered values.

    Kevin

  • Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0
    edited July 2020

    @kthorngren Thank you

        { data: "rem_bal" },
         { data: "rem_bal_per",
    
         render: function (data, type, row, meta) {
                          return Math.round(row._rem_bal_per)+'%';
    
                       }
               },
                { data: null,
                 render: function (data, type, row)
    
                         {
    
                          var start_date = new Date(row.start_date);
                          var end_date = new Date(row.end_date);
                          var today = new Date() ;
    
                          var sec_start = start_date.getTime();
                          var sec_end = end_date.getTime();
                          var sec_today = today.getTime();
    
    
                          var total = sec_end - sec_start;
                           var elapsed = sec_today - sec_start;
                           var percent = Math.round(((total-elapsed)/total * 100)) + '%';
    
    
                            return percent ;
    

    I use this var plainArray = table.columns().data().toArray(); to access the columns/rows of data. But this doesn't show me the null values. for example, in the code above , I am able to access first two but not the thrid value (null).

    How can I access all the values of datatble inside one variable?. in this case all inside var PlainArray?

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    edited July 2020

    To access the "rendered" data you will use either cell().render() or cells().render(). You my need to access the "data" values separately from the rendered values and combine them.

    Kevin

  • Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0
    edited July 2020

    Thank you very much. I have tried few options but I will delete my comment. Will try to read the documentation properly and if there is any problem I will get back to you thank you

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    You need to specify the type parameter, such as display, for example:
    var plainArray1 = table.cells().render("display");

    Here is a running example:
    http://live.datatables.net/wobesota/1/edit

    Kevin

  • Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0

    Thank you @kthorngren
    works perfect. I forgot to add display.
    However, is it possible to add a break so each row is saved separately rather than everything gets saved in one array.

    Could possibly break the array in in two sub arrays, but is there is way to add break ?

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    The cells() API returns an array of the selected cells. Its not a row based API. There is not a Datatables API I'm aware of to do what you are asking. You will need to create a JS loop to create a row based array of arrays.

    Kevin

  • Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0

    Thank you .

    I tried to run this loop, however with each row iteration, it is still outputting the render data in one single array

          table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
    
           var data = table.cells().render('display').toArray(); 
    
            console.log(data);
        } );
    
  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    edited July 2020

    Like I said you will need a Javascript solution. Take a look at this Stack Overflow thread for some ideas.

    Kevin

This discussion has been closed.