pass gridmodel for export in ajax request

Hi,

I want export a grid in excel, with the grouping and header stacker.... but I need modify the excel result.

So I create a function that export the grid and modify the excel. I call this function in ajax request.

The problem is that when I pass the gridmodel, the header stacker doesn't work in export function.

I think that the problem is in how I pass the grid model, but I don't know that is wrong.

I attach an example. The external button export without headerts stack but the toolbar button works fine.

Thanks

Attachment: GanttHeaderStacker_d2aac472.zip

3 Replies

VA Venkatesh Ayothi Raman Syncfusion Team January 9, 2018 12:23 PM UTC

Hi Manolo, 

Thanks for using Syncfusion products. 

We went through your project that you have shared for us and found that you are using Stacked headers in the Grid. If we use stacked headers then we have added the stackedHeaderColumn data in our source side for correctly serialize the Stacked headers in server side. So, only its works in normal Exporting and doesn’t in External Exporting through button. 
So, we have achieved your requirement using by adding the stackedHeaderColumn in the clone model property as named StackedHeaderRow like as follows, 
  function onExport() 
    { 
        
        var url = '@(Url.Action("ExportButton", "Grid"))'; 
 
        . .  . 
        var modelClone = $.extend(true, {}, grid.model); 
        . .  . 
        if (modelClone.showStackedHeader) { 
            modelClone.stackedHeaderRow = modelClone.stackedHeaderRows; 
            for (var i = 0; i < modelClone.stackedHeaderRow.length; i++) { 
                modelClone.stackedHeaderRow[i].stackedHeaderColumn = modelClone.stackedHeaderRow[i].stackedHeaderColumns; 
                var a = modelClone.stackedHeaderRow[i].stackedHeaderColumn; 
                for (var j = 0; j < a.length; j++) { 
                    modelClone.stackedHeaderRow[i].stackedHeaderColumn[j].column = $.isArray(a[j].column) ? a[j].column : a[j].column.split(','); 
                } 
            } 
        } 
 
        $.ajax({ 
            dataType: 'JSON', 
            type: 'POST', 
            url: url, 
            data: { gridModel: JSON.stringify(modelClone) }, 
            success: function (result) { 
. .  . 
            }, 
            error: function (jqXHR, textStatus, errorThrown) { 
            } 
        }); 
 
    } 
</script> 

We have also modified your sample which you have shared for us and it can be download form following link, 
  
Regards, 
Venkatesh Ayothiraman.  



MA Manolo January 11, 2018 08:20 AM UTC

Thanks!


RS Renjith Singh Rajendran Syncfusion Team January 12, 2018 04:50 AM UTC

Hi Manolo, 

We are happy to hear that your requirement has been achieved.  

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 


Loader.
Up arrow icon