We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Display add button in toolbar

Hi, Can i know how to show add button in toolbar if no record in database and hide add button when they have the record?
Thank you.

3 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team December 2, 2019 12:25 PM UTC

Hi Muhamad, 
Greetings from syncfusion support 
Query : show add button in toolbar if no record in database and hide add button when they have record 
We have analyzed your query, and suggest you to use the beforeDataBound event and hideitem() method to achieve your requirement. Here we have hide the toolbar item “Add”, in the beforeDataBound event when there is some records in database. By default, the toolbar item “Add” will shown even in no record and having records in database. So by the below procedure, you can show/hide the Add button in toolbar. 
<ejs-grid id="grid" dataSource="ViewBag.DataSource" beforeDataBound="beforeDataBound" toolbar="@(new List<string>() { "Add"})"> 
    <e-grid-editSettings allowAdding="true"></e-grid-editSettings> 
        <e-grid-column field="OrderID" headerText="Order ID" type="number" textAlign="Right" width="120"></e-grid-column> 
        <e-grid-column field="CustomerID" headerText="Customer ID" type="string" width="140"></e-grid-column> 
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="120"></e-grid-column> 
        <e-grid-column field="OrderDate" headerText="Order Date" format='yMd' textAlign="Right" width="140"></e-grid-column> 
    function beforeDataBound(args) { 
        if (args.count > 0) {                                 // check the record in database 
            var data = this.toolbar.indexOf('Add');           // get the Add button indexof value 
            this.toolbarModule.toolbar.hideItem(data, true);  // pass the value into the hideitem method as parameter and set to true 

Thavasianand S. 

MA Muhamad Adam Fakhrullah Nik Mohamad December 20, 2019 08:37 AM UTC

Thank you for your cooperation. Its worked

TS Thavasianand Sankaranarayanan Syncfusion Team December 20, 2019 08:58 AM UTC

Hi Muhamad, 
Thanks for your update. 
We are happy that the problem has been resolved at your end. 
Thavasianand S.  

Live Chat Icon For mobile
Up arrow icon