How to switch different themes in JavaScript Grid?
This knowledge base explains how to dynamically change themes in Grid component in the same application.
The names of the Syncfusion themes have been displayed in the dataSource of a DropDownList component. You can dynamically apply a different theme to the Grid component based on the selected theme from the DropDownList. The href path of the external style sheet link tag can be changed based on the selected theme value from the DropDownList, and the Grid can then be loaded with the selected theme.
In this demo, you can change the href path of the external style sheet link tag by using the select event of the DropDownList component.
let dropDownListObject: DropDownList = new DropDownList({ //Set the themes to the dataSource property. dataSource: themes, width: 190, select: function (e) { if (e.itemData.value === 'Material') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/material.css'; } else if (e.itemData.value === 'MaterialDark') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/material-dark.css'; } else if (e.itemData.value === 'Fabric') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/fabric.css'; } else if (e.itemData.value === 'FabricDark') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/fabric-dark.css'; } else if (e.itemData.value === 'Bootstrap') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/bootstrap.css'; } else if (e.itemData.value === 'BootsrapDark') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/bootstrap-dark.css'; } else if (e.itemData.value === 'Bootstrap4') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/bootstrap4.css'; } else if (e.itemData.value === 'Bootstrap5') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/bootstrap5.css'; } else if (e.itemData.value === 'Bootstrap5Dark') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/bootstrap5-dark.css'; } else if (e.itemData.value === 'Tailwind') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/tailwind.css'; } else if (e.itemData.value === 'TailwindDark') { document.getElementById('theme').href = 'https://cdn.syncfusion.com/ej2/tailwind-dark.css'; } }, // Set placeholder for the DropDownList input element. placeholder: 'Select a theme', }); dropDownListObject.appendTo('#ddlelement');
Output
You can find the sample here
Documentation
https://ej2.syncfusion.com/documentation/grid/getting-started
https://ej2.syncfusion.com/documentation/drop-down-list/getting-started
Conclusion
I hope you enjoyed learning about how to switch different themes in JavaScript Grid.
You can refer to our JavaScript Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Grid example 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!