ParamQuery grid support forum

General Category => Bug Report => Topic started by: jkoci@volny.cz on November 17, 2014, 07:18:31 pm

Title: tableToArray() error when table contains another table
Post by: jkoci@volny.cz 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
Title: Re: tableToArray() error when table contains another table
Post by: paramvir on November 18, 2014, 04:33:38 pm
tableToArray doesn't support nested HTML tables currently.
Title: Re: tableToArray() error when table contains another table
Post by: jkoci@volny.cz 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
      }
   };