Author Topic: Table export button if the implementation is not in the toolbar?  (Read 2151 times)

dreams

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 21
    • View Profile
Table export button if the implementation is not in the toolbar?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6113
    • View Profile
Re: Table export button if the implementation is not in the toolbar?
« Reply #1 on: April 02, 2020, 08:58:42 am »
To call a grid method from an external button, first you need reference to grid variable.

Code: [Select]
var grid = $( selector ).pqGrid( 'instance' );

//now call grid method.
grid.methodName( params );


dreams

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Table export button if the implementation is not in the toolbar?
« Reply #2 on: April 02, 2020, 09:22:03 am »
Thank you very much for your reply!I am a front end novice, did it your way, but still not right, request guidance.
            // 导出
            $('#Export').on('click', function () {
                var grid = $("#gridtable").pqGrid('instance');


                //alert(JSON.stringify(grid));
                //now call grid method.
                gridlistener();
error:
TypeError: grid.listener is not a function

                toolbar: {
                    items: [
                        {
                            type: 'button',
                            label: "Export to Excel",
                            icon: 'ui-icon-arrowthickstop-1-s',
                            listener: function () {

                                var blob = this.exportData({
                                    //url: "/pro/demos/exportData",
                                    format: 'xlsx',
                                    render: true,
                                    type: 'blob'
                                });
                                saveAs(blob, "销售跟踪表.xlsx");
                            }
                        }]
                },   

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6113
    • View Profile
Re: Table export button if the implementation is not in the toolbar?
« Reply #3 on: April 02, 2020, 10:10:00 am »
If you want to share same function between toolbar button and external button:

Code: [Select]
function exportData(){
  var blob = this.exportData({
      //url: "/pro/demos/exportData",
      format: 'xlsx',
      render: true,
      type: 'blob'
  });
  saveAs(blob, "销售跟踪表.xlsx"); 
}

Code: [Select]
$('#Export').on('click', function () {
   var grid = $("#gridtable").pqGrid('instance');
   exportData.call( grid );     
}) 

Code: [Select]
toolbar: {
                    items: [
                        {
                            type: 'button',
                            label: "Export to Excel",
                            icon: 'ui-icon-arrowthickstop-1-s',
                            listener: exportData
                        }]
                },   
« Last Edit: April 02, 2020, 10:24:09 am by paramvir »

dreams

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Table export button if the implementation is not in the toolbar?
« Reply #4 on: April 02, 2020, 01:28:45 pm »
The problem has been solved, thank you very much!