This is a migrated thread and some comments may be shown as answers.

Grid tag helper export excel not working

1 Answer 491 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yannick
Top achievements
Rank 1
Veteran
Yannick asked on 01 Jun 2020, 08:03 PM

Hi ,

 

I am trying to use the export feature of the grid using tag helper but somehow I can't make it work using tag helper or even jquery

 

<toolbar>
    <toolbar-button name="excel"></toolbar-button>
</toolbar>
<excel file-name="Kendo.xlsx" filterable="true" proxy-url="/PlanCodeGroup/Excel_Export_Save" />

 

my entire grid

<kendo-grid name="plancodegroupgrid" height="600" on-data-bound="dataBound" on-remove="onremove">
    <datasource type="DataSourceTagHelperType.Ajax" server-filtering="true" server-paging="true" page-size="100" on-request-end="onrequestend">
        <transport>
            <read url="planCodeGroup/PlanCodeGroup_Read" />
            <update url="planCodeGroup/PlanCodeGroup_Update" />
        </transport>
        <schema>
            <model id="PlanCodeGroupID">
                <fields>
                    <field name="PlanCode" editable="false"></field>
                    <field name="RateScaleCode" editable="false"></field>
                    <field name="PolicyTypeCode" editable="false"></field>
                    <field name="RiskIntegrityGroupPrefixCode"></field>
                    <field name="SystemName" editable="false"></field>
                    <field name="StartDate" editable="false" type="date"></field>
                    <field name="EndDate" type="date"></field>
                </fields>
            </model>
        </schema>
    </datasource>
    <toolbar>
        <toolbar-button name="excel"></toolbar-button>
    </toolbar>
    <excel file-name="Kendo.xlsx" filterable="true" proxy-url="/PlanCodeGroup/Excel_Export_Save" />
    <sortable enabled="true" mode="multiple" indexes="true" />
    <filterable enabled="true" mode="row" />
    <editable mode="inline" confirmation="false" />
    <columns>
        <column field="PlanCode" title="@localizer["PlanCode"].Value">
            <filterable>
                <cell show-operators="false"></cell>
            </filterable>
        </column>
        <column width="150" field="RateScaleCode" title="@localizer["RateScale"].Value">
            <filterable>
                <cell show-operators="false"></cell>
            </filterable>
        </column>
        <column width="150" field="PolicyTypeCode" title="@localizer["PolicyType"].Value">
            <filterable>
                <cell show-operators="false"></cell>
            </filterable>
        </column>
        <column width="150" field="SystemName" title="@localizer["System"].Value">
            <filterable>
                <cell show-operators="false"></cell>
            </filterable>
        </column>
        <column field="RiskIntegrityGroupPrefixCode" editor="riskIntegrityGroupPrefixCodeEditor" title="@localizer["GroupPrefix"].Value">
            <filterable>
                <cell show-operators="false"></cell>
            </filterable>
        </column>
        <column field="StartDate" title="@localizer["Start Date"].Value" format="{0:MM/dd/yyyy}">
            <filterable>
                <cell show-operators="false"></cell>
            </filterable>
        </column>
        <column field="EndDate" title="@localizer["EndDate"].Value" format="{0:MM/dd/yyyy}">
            <filterable>
                <cell show-operators="false"></cell>
            </filterable>
        </column>
        <column width="150">
            <commands>
                <column-command text=" " name="edit"></column-command>
                <column-command text=" " name="destroy"></column-command>
            </commands>
        </column>
    </columns>
    <scrollable height="auto" enabled="true" />
</kendo-grid>


finally my controller
I can see my Read Action being read when I click the export button but after that nothing happen.

I even try via jquery to do a grid.SaveAsExcel(). same result nothing happen also no errors in console.

public IActionResult PlanCodeGroup_Read([DataSourceRequest] DataSourceRequest request)
{
    var plancodeGroups = _mapper.Map<List<PlanCodeGroupModel>>(_planCodeService.GetAllPlanGroups());
 
    return Json(plancodeGroups.ToDataSourceResult(request));
}
 
[HttpPost]
public ActionResult Excel_Export_Save(string contentType, string base64, string fileName)
{
    var fileContents = Convert.FromBase64String(base64);
 
    return File(fileContents, contentType, fileName);
}

1 Answer, 1 is accepted

Sort by
1
Nikolay
Telerik team
answered on 04 Jun 2020, 11:05 AM

Hello Yannick,

Thank you for sharing the Grid declaration.

Unless you set ForceProxy(true) in the export settings, the ProxyUrl setting will not be used in most scenarios. The proxy method is used to save the Excel file through the server in browsers that don't support local file saving (IE 10, Safari). If you run your project in such browser with the current configuration, a request will be made to the provided URL, which will result in a 404 error, and no file will be saved.

The usage of the proxyUrl and forceProxy settings is described in detail in the following article about Kendo UI:

For your convenience, I am attaching a sample project implementing a TagHelper Grid with Excel export functionality.

Let me know you have any questions.

Regards,
Nikolay
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Yannick
Top achievements
Rank 1
Veteran
Answers by
Nikolay
Telerik team
Share this question
or