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

ejGrid allow insertion of only one record

I want to disable the add button when the number of records is greater than zero

5 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team June 19, 2019 07:09 AM UTC

Hi Ali,  

Thanks for contacting Syncfusion support.  

Query: “I want to disable the add button when the number of records is greater than zero 

As per your requirement we have disabled the Add toolbar item using dataBound event and actionComplete event of Grid. Refer the below code example. 

let grid: Grid = new Grid( 
            dataSource: [], 
            editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal', newRowPosition: 'Top' }, 
            allowPaging: true, 
            dataBound: function(args){ 
              if(grid.getCurrentViewRecords().length > 0)// to disbale the add toolbar during intial rendering  
            actionComplete: function(args){ 
              if(args.requestType == "save"){// to disbale the toolbar when a record is added 
            pageSettings: { pageCount: 5 }, 

For your convenience we have prepared sample which can be referred below  

Refer our documentation for your reference 

Note: Please clarify whether you have using ej 1 Grid or ej 2 Grid in your application ?. In the above we have provided the solution for ej 2 Grid. 

Please get back to us if you have further queries.  

Thavasianand S.  

AO Ali Ossaily June 19, 2019 07:15 AM UTC

Thanks for your support , kindly note that I'm using ej1 Grid

MP Manivannan Padmanaban Syncfusion Team June 20, 2019 09:41 AM UTC

Hi Ali, 

Thanks for the details. 

As per your request, we have prepared the solution in EJ 1 Grid. Kindly refer the below code example, 

<script type="text/javascript"> 
    $(function () { 
            dataSource: window.gridData, 
            dataBound: function (args) { 
                if (this.model.currentViewData.length > 0) 
                    $("#Grid_add").addClass("e-disable") // Use your grid ID here. 
            allowPaging: true, 
            editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, 
            toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit, ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] }, 
            columns: [ 

Help documentation Link, 

Manivannan Padmanaban.  

AO Ali Ossaily June 20, 2019 10:01 AM UTC

Thanks Alot , it works

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team June 21, 2019 04:28 AM UTC

Hi Ali,  

Thanks for your update. Please get back to us if you need any further assistance. 

Farveen sulthana T 

Live Chat Icon For mobile
Up arrow icon