javascript - Making a HTML_PARSER to work in widget DataTable -


so i'm trying parse html table yui 3 datatable widget, modifiyng widget html_parser object.

html

<div id="table"> <table> <thead> <tr>     <th>tipo</th>      <th>codigo</th>      <th>descripcion</th>     <th>impuesto para la venta</th>     <th>precio</th>     <th>precio con iva</th>     <th>cantidad</th> </tr> </thead> <tbody> <tr>     <td>producto</td>      <td>1</td>      <td>7</td>      <td>12</td>      <td>7.00</td>      <td></td>      <td>7</td>  </tr> </tbody> </table> </div> 

javascript

y.datatable.html_parser = {     columns:function(srcnode) {         var cols = [];          srcnode.all("th").each(function(th){             var col = {                 // sets column "key" contents of th spaces removed                 key:    th.gethtml().replace(/\s+/g, '').tolowercase(),                    label:  th.gethtml()                                };             cols.push(col);         });         return cols;     },     data:function(srcnode) {         var data = [];         srcnode.all("tbody tr").each(function(tr){             var col = {};             tr.all("td").each( function(td_item, td_index){                // extracts "key" name column based on it's td index                 var datakey = y.datatable.html_parser.cols[td_index].key,                         data = td_item.gethtml();                                // sets "key:data" td element ...                     col[datakey] = data;                 });             data.push(col);           });         return data;    } };  new y.datatable({srcnode:'#table'}).render('#table'); 

there must wrong. maybe misread documentation. need help. playground

when getting datakey, calling method cols instead of columns. way, shouldn't call each cell, slow. column keys array before looping on data cells , save them in local variable. other that, looks me though haven't done in ages , might forgetting something.

suerte


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -