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

Adding Toolbar Template Removes Excel Button

5 Answers 430 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kencox
Top achievements
Rank 1
kencox asked on 02 Jun 2018, 08:55 PM

I'm trying to add a toolbar Template to the MVC Grid toolbar in addition to the Excel button.

When I add the template, the Excel button disappears. 

How can I have both?

Code below.

Thanks!

.ToolBar(toolbar =>
{
    toolbar.Excel();
    toolbar.Template("<button type='button' onclick='customCommand()'>Button Here</button>");
})

 

5 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 05 Jun 2018, 01:23 PM
Hello Ken,

The described behavior is expected.

When a toolbar template is specified within the configuration of the toolbar the whole content of the toolbar is replaced with the toolbar. In other words, any other commands will be ignored.

A possible solution to use both excel command and a custom toolbar template is to add an excel button within the toolbar template.

e.g.

.ToolBar(toolbar =>
{
toolbar.Template(@"
<button type='button' onclick='customCommand()'>Button Here</button>
<a role='button' class='k-button k-button-icontext k-grid-excel' href='#'><span class='k-icon k-i-file-excel'></span>Export to Excel</a>
");
})


Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jessica
Top achievements
Rank 1
answered on 31 Jul 2018, 11:14 PM

If done this way with (the as "#") can you still have the excel settings on the grid as follows: 

.Excel(excel => excel
                              .FileName("Filename.xlsx")
                              .Filterable(true)
                              .ProxyURL(Url.Action("Excel_Export_Save", "Grid"))
                              .AllPages(true)
                          )

Thus, it would use Url.Action in the controller and all the other settings?

 

0
Georgi
Telerik team
answered on 01 Aug 2018, 01:53 PM
Hi Jessica,

Yes, the Excel configuration of the grid does not depend on the toolbar command. The only requirement is to add the k-grid-excel class to the excel export command as the click event is attached as follows:

container.on(CLICK + NS, ".k-grid-excel", function(e) {
    e.preventDefault();
 
    that.saveAsExcel();
});


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jessica
Top achievements
Rank 1
answered on 01 Aug 2018, 03:56 PM

Thank you! 

On the href='#' do we put '\\', as href='\\#' because without it I was getting an error in the grid?

0
Georgi
Telerik team
answered on 03 Aug 2018, 05:52 AM
Hello Jessisca,

Thank you for correcting me.

Indeed the toolbar template is evaluated to a Kendo Template on the client. Therefore all # literals which are not part of any binding expression should be escaped.


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
kencox
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Jessica
Top achievements
Rank 1
Share this question
or