DescriptionThis Knowledge Base explains the way to add or remove the custom controls (button, dropdown….) in the ribbon in spreadsheet. SolutionIt can be achieved by using addTabGroup and removeTabGroup methods.The following code examples demonstrates that how to perform this operation.
1. Render Spreadsheet control.
JS
<ul id="targetData"> <li><span>User</span></li> <li><span>Guest</span></li> <li><span>Admin</span></li> </ul> <div id="Spreadsheet"></div> <script type="text/javascript"> $(function () { $("#Spreadsheet").ejSpreadsheet({ scrollSettings: { height: "100%", width: "100%" }, sheets: [{ // window.data from http://js.syncfusion.com/demos/web/scripts/xljsondata.min.js file rangeSettings: [{ dataSource: window.data, showHeader: true }] }], loadComplete: "onLoadComplete" }); }); </script>
MVC
<ul id="targetData"> <li><span>User</span></li> <li><span>Guest</span></li> <li><span>Admin</span></li> </ul> <div id="Spreadsheet"></div> <div style="height:550px;"> @(Html.EJ().Spreadsheet<object>("Spreadsheet") .ScrollSettings(scroll => { scroll.Height("100%"); scroll.Width("100%"); }) .Sheets(sheet => { sheet.RangeSettings(range => { range.Datasource((IEnumerable<object>)ViewBag.Datasource).Add(); }).Add(); }) .ClientSideEvents(events => events.LoadComplete("onLoadComplete")) ) </div>
ASP
<ul id="targetData"> <li><span>User</span></li> <li><span>Guest</span></li> <li><span>Admin</span></li> </ul> <ej:Spreadsheet ID="Spreadsheet" runat='server'> <ScrollSettings Width="100%" Height="100%" /> <ClientSideEvents LoadComplete="onLoadComplete" /> </ej:Spreadsheet>
2. In the loadComplete client side event, we can customize the controls and add it to ribbon by using addTabGroup method.
JS
<script type="text/javascript"> function onLoadComplete(args) { var tabIndex = 2, groupIndex = 4; var ribbonGrp = { alignType: ej.Ribbon.AlignType.Rows, text: "Custom button", content: [{ groups: [{ id: "customBtn", splitButtonSettings: { arrowPosition: ej.ArrowPosition.Bottom, text: "login", targetID: "targetData", buttonMode: ej.ButtonMode.Dropdown, contentType: "textandimage", prefixIcon: "e-icon e-login e-uiLight" } }], defaults: { type: ej.Ribbon.Type.SplitButton } }] }; this.XLRibbon.addTabGroup(tabIndex, ribbonGrp, groupIndex); // To add the tab group in the ribbon INSERT tab. } </script>
|
This page will automatically be redirected to the sign-in page in 10 seconds.