jQWidgets Forums

jQuery UI Widgets Forums Grid Export data from jqxgrid

Tagged: 

This topic contains 3 replies, has 3 voices, and was last updated by  raghu501 10 years, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Export data from jqxgrid #46326

    jedipalm
    Participant

    I want to export all data in my jqxgrid into json and send it to another page via AJAX. My problem is when I click export button, the data in the grid and data before export was not the same. It change float number to Interger. Here is my code:

    javascript:

    
    $('#export_bt').on('click', function(){
      var row = $("#jqxgrid").jqxGrid('exportdata', 'json');
      $('#debug').html(row);
      console.log(row);
    });
    
    var tableDatas = [
      {"timestamp":"06:00:00","A":99.49,"B":337.77,"C":155.98},
      {"timestamp":"07:00:00","A":455.67,"B":474.1,"C":751.68},
      {"timestamp":"08:00:00","A":1071.02,"B":598.14,"C":890.47}
    ];
    
    var tableDatafields = [
      {"name":"timestamp","type":"string"},
      {"name":"A","type":"number"},
      {"name":"B","type":"number"},
      {"name":"C","type":"number"}
    ];
    
    var tableColumns = [
      {"text":"Times","datafield":"timestamp","editable":"false","align":"center","cellsalign":"center","width":150},
      {"text":"A","datafield":"A","editable":"false","align":"center"},
      {"text":"B","datafield":"B","editable":"false","align":"center"},
      {"text":"C","datafield":"C","editable":"false","align":"center"}
    ];
    
    function setTableData(table_data,table_column,table_datafields)
    {
      sourceTable.localdata = table_data;
      sourceTable.datafields = table_datafields;
      dataAdapterTable = new $.jqx.dataAdapter(sourceTable);
      $("#jqxgrid").jqxGrid({columns:table_column});
      $("#jqxgrid").jqxGrid('updatebounddata');
      $('#jqxgrid').jqxGrid('sortby', 'timestamp', 'asc');
      $("#jqxgrid").jqxGrid('autoresizecolumns');
    
      for(var i=0;i<table_column.length;i++){
        $('#jqxgrid').jqxGrid('setcolumnproperty',table_column[i].datafield,'cellsrenderer',cellsrenderer);
      }
    }
    
    var cellsrenderer = function (row, columnfield, value, defaulthtml, columnproperties) {
      if (value||value===0) {
        return value;
      }
      else {
        return '-';
      }
    };
    
    var sourceTable ={ localdata: '', datatype: 'array'};
    
    var dataAdapterTable = new $.jqx.dataAdapter(sourceTable);
    dataAdapterTable.dataBind();
    
    $("#jqxgrid").jqxGrid({
      width: '500',
      autoheight:true,
      source: dataAdapterTable,
      sortable: true,
      columnsresize: false,
      selectionmode: 'none',
      columns: [{ text: '', datafield: 'timestamp', width:'100%' , editable: false, align:'center'}]
    });
    
    setTableData(tableDatas,tableColumns,tableDatafields);
    

    html:

    
    <div id="jqxgrid"></div>
    <button id="export_bt">Export</button>
    <div id="debug"></div>
    

    Export data from jqxgrid #46333

    jedipalm
    Participant
    Export data from jqxgrid #46336

    Peter Stoev
    Keymaster

    Hi jedipalm,

    Thanks for the feedback! If you need just to export the data to JSON, set the dataType to String.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Export data from jqxgrid #70478

    raghu501
    Participant

    Hi,

    I want to pass the result of var aupexportdata = $(“#jqxgrid”).jqxGrid(‘exportdata’, ‘xls’);
    to action method in ASP.NET MVC ,this method
    would return Excel File.is there any feature to pass the ‘aupexportdata’ to contoller.
    i am trying to pass this by using forms, i am unable to get the ‘exportdata’ result in action method.please help me.

    Regards
    Raghu

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.