jQWidgets Forums

jQuery UI Widgets Forums Grid Export data with cellsrenderer value.

This topic contains 5 replies, has 3 voices, and was last updated by  soojung 8 years, 4 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • Export data with cellsrenderer value. #56504

    vinothr
    Participant

    hi,

    I have a jqxgrid with cellsrenderer for total column. Everything working fine.
    Now I want to export data to a local variavle as JSON string. Here comes the problem, If try $(“#jqxgrid”).jqxGrid(‘exportdata’, ‘json’); the total column comes with “”(empty) value.

    any other way to achieve this or any clue please.


    Peter Stoev
    Keymaster

    Hi vinothr,

    Exporting result of “cellsrenderer” callback function is not possible, because “cellsrenderer” returns HTML, not Text.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    vinothr
    Participant

    hi peter,

    but i require those values. is there any other way to do this.

    Vinoth R


    Peter Stoev
    Keymaster

    Hi vinothr,

    The exportdata method accepts an Array of Rows as parameter so you can pass what kind of data would be exported. My suggestion is: Get the Grid’s rows by using the “getrows” method. Make the necessary customizations in that array in order to fit to your requirements and pass it to the “exportdata” method call in the way pointed out in the Grid’s API Docs.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Export data with cellsrenderer value. #90408

    soojung
    Participant

    Hi Peter,
    I write this code as you mentioned. But the result is same. Column value is different that I want.
    What part did I mistake?

    $btnExcel.click(function () {
        var gridRows = $jqxGrid.jqxGrid('getrows');
        $jqxGrid.jqxGrid('exportdata', 'xls', 'Magam', true, gridRows, false, null, 'utf-8');
    });
    Export data with cellsrenderer value. #90431

    soojung
    Participant

    Ah now I understand your intend. I solve problem like this.
    I test on your ‘getrows’ jsfiddle source.
    Change javascript code.

    var data = generatedata(5);
    var source = {
      localdata: data,
      datafields: [{
        name: 'firstname',
        type: 'string'
      }, {
        name: 'lastname',
        type: 'string'
      }, {
        name: 'productname',
        type: 'string'
      }, {
        name: 'date',
        type: 'date'
      }, {
        name: 'quantity',
        type: 'number'
      }, {
        name: 'price',
        type: 'number'
      }],
      datatype: "array"
    };
    
    var cellsrenderer_MS = function(row, column, value, defaulthtml, columnproperties) {
      var rowData = $("#jqxgrid").jqxGrid('getrowdata', row);
      return '<div class="cellren_height">' + rowData.firstname + ' / ' + rowData.lastname + '</div>';
    }
    
    var adapter = new $.jqx.dataAdapter(source);
    $("#jqxgrid").jqxGrid({
      width: 500,
      height: 100,
      theme: 'energyblue',
      source: adapter,
      sortable: true,
      selectionmode: 'singlecell',
      columns: [{
        text: 'First Name',
        datafield: 'firstname',
        columngroup: 'Name',
        width: 90,
        cellsrenderer: cellsrenderer_MS
      }, {
        text: 'Last Name',
        columngroup: 'Name',
        datafield: 'lastname',
        width: 90
      }, {
        text: 'Product',
        datafield: 'productname',
        width: 170
      }, {
        text: 'Order Date',
        datafield: 'date',
        width: 160,
        cellsformat: 'dd-MMMM-yyyy'
      }, {
        text: 'Quantity',
        datafield: 'quantity',
        width: 80,
        cellsalign: 'right'
      }, {
        text: 'Unit Price',
        datafield: 'price',
        cellsalign: 'right',
        cellsformat: 'c2'
      }]
    });
    
    $("#jqxbutton").jqxButton({
      theme: 'energyblue',
      width: 200,
      height: 30
    });
    
    $('#jqxbutton').click(function() {
      var rows = $('#jqxgrid').jqxGrid('getrows');
      rows[0].firstname = rows[0].firstname + ' / ' + rows[0].lastname;
      $('#jqxgrid').jqxGrid('exportdata', 'xls', '마감', true, rows, false, null, "euc-kr");
    });
    

    Then you can export rendered data.

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

You must be logged in to reply to this topic.