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
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
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?
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
Thank you!
On the href='#' do we put '\\', as href='\\#' because without it I was getting an error in the grid?
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