Custom Command Button in Toolbars

3 Answers 10213 Views
Grid
Jessie
Top achievements
Rank 1
Jessie asked on 28 Nov 2012, 10:13 AM
Hi Guys,

Has any one attempted to add custom command button in the toolbar? Like the one seen in the inline editing, also how to wire up those command button to custom events.

Thanks,
Jessie

3 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 30 Nov 2012, 09:05 AM
Hi Jessie,

 
Basically you can add link with class "k-button" in the Toolbar template and use the click event for example to call custom function. Please check the example below:

.ToolBar(toolBar => toolBar.Template("<a class='k-button k-button-icontext' onclick='customCommand()' href='#'></span>Cutom Command</a>"))

function customCommand() {
    //execute your custom logic
}

Also please note that the Grid uses the jQuery Delegate to wire up the standard Grid commands to any link that contains the following classes:

  • for add record: k-grid-add
  • for delete: k-grid-delete
  • for update: k-grid-update
  • for edit: k-grid-edit
  • for cancel: k-grid-cancel
  • for batch editing cancel: k-grid-cancel-changes
  • for batch editing save: k-grid-save-changes

For example the following template will add new record to the Grid and also execute your custom command:

.ToolBar(toolBar => toolBar.Template("<a class='k-button k-button-icontext k-grid-add' href='#' onlick='customCommand()'>Add new record</a>"))


Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Sucre
Top achievements
Rank 1
commented on 10 Jan 2013, 08:10 AM

Hi Vladimir Iliev
   How to do this by js.
   My toobar code :toolbar: [{ name: "create", text: "Add" },{ name: "edit", text: "Edit" }].But how to add custom events?
   Thanks,
   sucre.
Vladimir Iliev
Telerik team
commented on 14 Jan 2013, 06:34 AM

Hi Jessie,

 
Basically you should define Toolbar template and follow the guides from my previous post. For more information how to define Toolbar template you can check this demo.

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Narasimha
Top achievements
Rank 1
commented on 09 Mar 2016, 10:49 AM

How we write the same for Kendo UI grid with callback.
Vladimir Iliev
Telerik team
commented on 10 Mar 2016, 09:54 AM

Hello Jessie,

Please note that the same option is available for the Kendo UI Grid and the same template can be used inside it - for more information you can check the Grid API:

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
John
Top achievements
Rank 1
commented on 01 Jun 2017, 03:38 AM

The Dojo example at "Kendo UI Grid: toolbar.template option" doesn't seem to work.
Alex Hajigeorgieva
Telerik team
commented on 02 Jun 2017, 12:20 PM

Hi John,

Thank you for letting us know. I suppose it might have been a glitch with the Dojo as we recently made some changes. Now it seems to be up and running:


Thomas, alternatively, you may add a click handler or use the same approach as shown in the JavaScript API here:

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-toolbar.template

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Thomas
Top achievements
Rank 1
commented on 06 Jun 2017, 05:00 AM

Hi Alex,

I saw in the documentation the part where you redefine the entire template but the goal here was to keep the default method for creating a new entity in the toolbar and add a custom command.

.ToolBar(toolbar => {
            toolbar.Create().Text("Add option").HtmlAttributes(new { @style = "font-weight:normal" });
            toolbar.Custom().Text("Import").HtmlAttributes(new { href = "javascript:onImport(#=Id#);" });
})

 

Alex Hajigeorgieva
Telerik team
commented on 07 Jun 2017, 02:24 PM

Hi Thomas,

In this case, you may use the below alternative to attach a click handler:

.ToolBar(toolbar =>
{
  toolbar.Custom().Text("Import").Name("import").Url("#");
})
 
<script>
$(function () {
 $("#grid").find(".k-grid-toolbar").on("click", ".k-grid-import", function (e) {
   e.preventDefault();
   console.log("import clicked!");      
 });
});
</script>

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Vijaya Raju Manda
Top achievements
Rank 1
commented on 17 Oct 2018, 06:50 AM

Hi  Alex Hajigeorgieva,

onclicking of this import button i need to render  cshtml template popup which can do create, updates please help on this?

<script>
$(function () {
 $("#grid").find(".k-grid-toolbar").on("click", ".k-grid-import", function (e) {
   e.preventDefault();
   //console.log("import clicked!");  

// here want to call template that is custom add multiple records button. 
 });
});
</script>

below is my code

 .ToolBar(toolbar =>
                {
                    toolbar.Create();
                    toolbar.Custom().Name("multipleRecords").Text("Add multiple records");
                    toolbar.Custom().Name("expandAll").Text("Expand All");
                    toolbar.Custom().Name("collapseAll").Text("Collapse All");
                })
                .ClientDetailTemplateId("orderPhrase-template")
                .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("OrderPhraseSet").AdditionalViewData(new { OrderPhraseSetId = "#=OrderPhraseSetId#" }).DisplayDeleteConfirmation(false))
                .DataSource(dataSource => dataSource
                .Ajax()
                .Model(model =>
                {
                    model.Id(c => c.OrderPhraseSetId);
                })
                .Read(read => read.Action("ReadPhraseSets", "OrderPhrase").Data("filterOrderId"))
                .Create(create => create.Action("CreatePhraseSet", "OrderPhrase").Data("filterOrderId"))
                .Update(update => update.Action("UpdatePhraseSet", "OrderPhrase"))
                .Destroy(destroy => destroy.Action("DestroyOrderPhraseSet", "OrderPhrase"))
                .Events(e => e
                .Error("errorHandler")
                .RequestEnd("onRequestEndPhraseSet"))
                .Sort(s =>
                {
                    s.Add("SortOrder");
                })
                )
                .Events(e => e

=========================

 $(function () {
        $('.k-grid-multipleRecords').click(function (e) {
           //here need to render 'OrderPhraseSet.cshtml' separate (this is not a action just template ) template.
        })
    })

 

Alex Hajigeorgieva
Telerik team
commented on 19 Oct 2018, 07:23 AM

Hello, Vijaya,

You may use the Kendo UI Window to load content with ajax:

https://demos.telerik.com/aspnet-mvc/window/ajax

IYou would need to add the window widget on the page and when the custom toolbar button is  clicked, you can use the client-side open() method to show it in a modal:

var wnd = $("#customPopup").data("kendoWindow");
wnd.center().open();

Let me know in case you had something else in mind.

Kind Regards,
Alex Hajigeorgieva
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
Sanket
Top achievements
Rank 1
answered on 08 Apr 2013, 11:39 AM
.ToolBar(toolBar => toolBar.Template("<a class='k-button k-button-icontext' onclick='customCommand()' href='#'></span>Cutom Command</a>"))


doesnt fire the  customCommand() event  try with 


.ToolBar(toolBar =>
                                {
                              
                                     toolBar.Custom().Name("DeleteI").Text("Delete").Url("#").HtmlAttributes(new { onclick = "onDelete()" });
                              
                                })
0
Thomas
Top achievements
Rank 1
answered on 01 Jun 2017, 07:36 AM

Redefining the href property of the link seems to work.

toolbar.Custom().Text("Import").HtmlAttributes(new { href = "javascript:onImport(#=Id#);" });

function onImport(e)
    {
        alert(e);
    }

Tags
Grid
Asked by
Jessie
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Sanket
Top achievements
Rank 1
Thomas
Top achievements
Rank 1
Share this question
or