javascript - how to convert a div values into a csv file in a specific file name and specific path -


i having div element consists of table. table values taken fron json array , have create new row of array , displayed ina table using export button have export table valus in csv file in specific filename , in specific path. export:

$("#export").click(function(e) {     alert('inside export method');     var = document.createelement('a');     //getting data our div contains html table     var data_type = 'data:application/vnd.ms-excel';     var table_div = document.getelementbyid('exportdata');     var table_html = table_div.outerhtml.replace(/ /g, '%20');     alert(table_html);      a.href = data_type + ', ' + table_html;     //setting file name     alert("pname"+pname);     a.download = 'export.xls';     alert('after got id');     //triggering function     a.click();      //just in case, prevent default behaviour     e.preventdefault();  });                  

this code xls have store values in csv file , name have specific , everytime of exporting valu should updated in same file last row.

html:

<div id="exportdata"> <table class="table table-bordered table-striped tablelink">  <thead>   <tr>     <td>       <a href="#" ng-click="sorttype = 'issueno'; sortreverse = !sortreverse">         issue no         <span ng-show="sorttype == 'issueno' && !sortreverse" class="fa fa-caret-down"></span>         <span ng-show="sorttype == 'issueno' && sortreverse" class="fa fa-caret-up"></span>       </a>     </td>     <td>       <a href="#" ng-click="sorttype = 'dateassigned'; sortreverse = !sortreverse">       date assigned         <span ng-show="sorttype == 'dateassigned' && !sortreverse" class="fa fa-caret-down"></span>         <span ng-show="sorttype == 'dateassigned' && sortreverse" class="fa fa-caret-up"></span>       </a>     </td>     <td>       <a href="#" ng-click="sorttype = 'assignedby'; sortreverse = !sortreverse">       assignedby         <span ng-show="sorttype == 'assignedby' && !sortreverse" class="fa fa-caret-down"></span>         <span ng-show="sorttype == 'assignedby' && sortreverse" class="fa fa-caret-up"></span>       </a>     </td>     <td>       <a href="#" ng-click="sorttype = 'issuetype'; sortreverse = !sortreverse">       issue type         <span ng-show="sorttype == 'issuetype' && !sortreverse" class="fa fa-caret-down"></span>         <span ng-show="sorttype == 'issuetype' && sortreverse" class="fa fa-caret-up"></span>       </a>     </td>     <td>       <a href="#" ng-click="sorttype = 'priority'; sortreverse = !sortreverse">       priority         <span ng-show="sorttype == 'priority' && !sortreverse" class="fa fa-caret-down"></span>         <span ng-show="sorttype == 'priority' && sortreverse" class="fa fa-caret-up"></span>       </a>     </td>     <td>       <a href="#" ng-click="sorttype = 'targetdate'; sortreverse = !sortreverse">       target date         <span ng-show="sorttype == 'targetdate' && !sortreverse" class="fa fa-caret-down"></span>         <span ng-show="sorttype == 'targetdate' && sortreverse" class="fa fa-caret-up"></span>       </a>     </td>     <td>       <a href="#" ng-click="sorttype = 'status'; sortreverse = !sortreverse">       status         <span ng-show="sorttype == 'status' && !sortreverse" class="fa fa-caret-down"></span>         <span ng-show="sorttype == 'status' && sortreverse" class="fa fa-caret-up"></span>       </a>     </td>     <td>       <a href="#" ng-click="sorttype = 'attachment'; sortreverse = !sortreverse">       attachment         <span ng-show="sorttype == 'attachment' && !sortreverse" class="fa fa-caret-down"></span>         <span ng-show="sorttype == 'attachment' && sortreverse" class="fa fa-caret-up"></span>       </a>     </td>     <td  style='visibility:hidden'>       <a href="#" ng-click="sorttype = 'description'; sortreverse = !sortreverse">       description         <span ng-show="sorttype == 'description' && !sortreverse" class="fa fa-caret-down"></span>         <span ng-show="sorttype == 'description' && sortreverse" class="fa fa-caret-up"></span>       </a>     </td>   </tr> </thead>  <tbody>   <tr ng-repeat="roll in sushi | orderby:sorttype:sortreverse | filter:searchcon">     <td ng-click="display(roll.issueno);"><a href="#">{{ roll.issueno }}</a></td>     <td>{{ roll.dateassigned }}</td>     <td>{{ roll.assignedby }}</td>     <td>{{ roll.issuetype}}</td>     <td>{{ roll.priority}}</td>     <td>{{ roll.targetdate}}</td>     <td>{{ roll.status}}</td>     <td>{{ roll.attachment}}</td>     <td style='visibility:hidden'>{{roll.description}}</td>   </tr>   <tr id="newr">   </tr> </tbody> 

using export button , file should replaces every time when new record stored in table

i suggest use angular-file-saver package saving file.

and better way iterate directly through model sushi not through generated html.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -