ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: dreams on April 02, 2020, 08:36:20 am

Title: Table export button if the implementation is not in the toolbar?
Post by: dreams on April 02, 2020, 08:36:20 am
Table export button if the implementation is not in the toolbar?
Title: Re: Table export button if the implementation is not in the toolbar?
Post by: paramvir 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 );

Title: Re: Table export button if the implementation is not in the toolbar?
Post by: dreams 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");
                            }
                        }]
                },   
Title: Re: Table export button if the implementation is not in the toolbar?
Post by: paramvir 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
                        }]
                },   
Title: Re: Table export button if the implementation is not in the toolbar?
Post by: dreams on April 02, 2020, 01:28:45 pm
The problem has been solved, thank you very much!