Articles in this section
Category / Section

How to add a template in ribbon backstage in Javascript Grid?

4 mins read

Description

This knowledge base explains how to add a template in ribbon backstage in JavaScript Grid

Solution

It can be achieved by using ‘loadComplete’ client-side event in the Spreadsheet. Here we have added button as a template in the ribbon backstage and we will update the template data by using “openTemplate()” method, when template button is clicked.

The following code example demonstrate how to add template in ribbon backstage,

 

HTML

 

 
<div id="Spreadsheet"></div>
 

 

JS

 

  1. Render the Spreadsheet control.

 

 
$("#Spreadsheet").ejSpreadsheet({
    loadComplete: "onLoadComplete"
});
 

 

RAZOR

 

 
@(Html.EJ().Spreadsheet<object>("Spreadsheet")
    .ClientSideEvents(
        events => events.LoadComplete("onLoadComplete")
    )
)
 

 

ASPX

 

 
<ej:Spreadsheet ID="Spreadsheet" runat="server">
    <ClientSideEvents LoadComplete="onLoadComplete" />
</ej:Spreadsheet>
 

 

JS

 

  1. Use “loadComplete” client-side event to add template in ribbon backstage.

 

 
function onLoadComplete() {
    var spreadsheetID = "Spreadsheet", backstageNewElem = $("#" + spreadsheetID + "_backstagetabnew"), backstageItem, templateID = spreadsheetID + "_bstab_template", buttonOption;
 
    //Adding Backstage Item 
    if (!backstageNewElem.find("#" + templateID).length) {
        backstageItem = '<div class="e-spreadsheet-template"><button id="' + templateID + '"></button><span></span></div>',
        buttonOption = { height: 120, width: 150, contentType: "textOnly", text: "Template", click: "openTemplate" };
        backstageNewElem.append(backstageItem);
        $("#" + templateID).ejButton(buttonOption);
    }
}
 
function openTemplate(args) {
    //To update template data in the Spreadsheet
    var spreadsheetID = "Spreadsheet", xlObj = $("#" + spreadsheetID).data("ejSpreadsheet"), sheetIdx = xlObj.getActiveSheetIndex(), templateData = { dataSource: [{ Product: "XYZ", Price: "2000", Quantity: "10", Price: "20", Amount: "200" }], showHeader: "true", startCell: "A1" };
    xlObj.updateRange(sheetIdx, templateData);
    $("#" + spreadsheetID + "_Ribbon").data("ejRibbon").hideBackstage();
}

 

The following is displayed as output of adding custom template in the Spreadsheet ribbon backstage.

 

spreadsheet ribbon backstage sample preview

Figure: Spreadsheet Ribbon Backstage.



Conclusion

I hope you enjoyed learning about how to add a template in ribbon backstage in JavaScript Grid.

You can refer to our JavaScript Grid page to know about its other groundbreaking feature representations and documentation, to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied