Author Topic: tableToArray() error when table contains another table  (Read 3519 times)

[email protected]

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 30
    • View Profile
tableToArray() error when table contains another table
« on: November 17, 2014, 07:18:31 pm »
I have something like this

<table><tr><td><table><tr><td>afashfjh</td></tr></table></td></tr></table>

when I use tableToArray, it generates doubled lines...

Thanks,

Jan

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: tableToArray() error when table contains another table
« Reply #1 on: November 18, 2014, 04:33:38 pm »
tableToArray doesn't support nested HTML tables currently.

[email protected]

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: tableToArray() error when table contains another table
« Reply #2 on: November 23, 2014, 04:55:43 pm »
temporary update for myself

   pq.tableToArray = function(tbl) {
      var $tbl = $(tbl);
      var colModel = [];
      var data = [];
      var cols = [];
      var widths = [];
      var $trfirst = $tbl.find("tr:first");
      var $trsecond = $tbl.find("tr:eq(1)");
      $trfirst.find("th,td").each(function(i, td) {
         var $td = $(td);
         var title = $td.html();
         var width = $td.width();
         var dataType = "string";
         var $tdsec = $trsecond.find("td:eq(" + i + ")");
         var align = $tdsec.attr("align");
         var obj = {
            title: title,
            width: width,
            dataType: dataType,
            align: align,
            dataIndx: i
         };
         colModel.push(obj);
      });
      $tbl.children("tbody").children("tr").each(function(i, tr) {
// ----- jk update
//      $tbl.find("tr").each(function(i, tr) {
//         if (i == 0) {
//            return
//         }
         var $tr = $(tr);
         var arr2 = [];
// ----- jk update
//      $tr.find("td").each(function(j, td) {
         $tr.children("td").each(function(j, td) {
              arr2.push($.trim($(td).html()));
         });
         data.push(arr2);
      });
      return {
         data: data,
         colModel: colModel
      }
   };