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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Display add button in toolbar

Thread ID:

Created:

Updated:

Platform:

Replies:

149578 Dec 2,2019 04:32 AM UTC Dec 20,2019 08:58 AM UTC ASP.NET Core - EJ 2 3
loading
Tags: DataGrid
Muhamad Adam Fakhrullah Nik Mohamad
Asked On December 2, 2019 04:32 AM UTC

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.

Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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. 
 
Index.cshtml 
 
 
<ejs-grid id="grid" dataSource="ViewBag.DataSource" beforeDataBound="beforeDataBound" toolbar="@(new List<string>() { "Add"})"> 
    <e-grid-editSettings allowAdding="true"></e-grid-editSettings> 
    <e-grid-columns> 
        <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> 
    </e-grid-columns> 
</ejs-grid> 
 
<script> 
    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 
        } 
         
    } 
</script> 
 
 

Regards 
Thavasianand S. 


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

Thank you for your cooperation. Its worked

Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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. 
 
Regards, 
Thavasianand S.  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon