Problem while restricting Add new Record button in RadGrid

8 posts, 0 answers
  1. Sandeep
    Sandeep avatar
    6 posts
    Member since:
    Apr 2016

    Posted 18 Apr Link to this post

    Hi 
    I am using batch edit grid.

    My requirement: I want to restrict the user to create the new row when the number of rows in grid view is more than the quantity (2 records). And also I want user to edit the existing rows.

    I am able to restrict the user from adding new rows more than number of records specified( In our case its 2 records).
    But the problem is I am not able to edit existing rows. 
    Below is the code.

    ASPX:

    <telerik:RadGrid ID="gvSerialNumberTracking" GridLines="None" runat="server" AllowPaging="false"OnBatchEditCommand="gvSerialNumberTracking_BatchEditCommand" OnItemCommand="gvSerialNumberTracking_ItemCommand" CssClass="gvPLC">
     
    <MasterTableView DataKeyNames="SerialNumber_ID,SerialNumber_DJ_ID" TableLayout="Auto" EditMode="Batch" AutoGenerateColumns="false"CommandItemDisplay="Top" ClientDataKeyNames="SerialNumber_ID">
                                                                            <BatchEditingSettingsEditType="Row" />                                                                      
     
    <Columns>
    <telerik:GridBoundColumn DataField="UnitSN" HeaderText="Unit SN" HeaderStyle-Width="100px" UniqueName="UnitSN"></telerik:GridBoundColumn>
     
                                                                                <telerik:GridBoundColumnDataField="Sub1" HeaderText="Sub1" HeaderStyle-Width="100px" UniqueName="Sub1"></telerik:GridBoundColumn>
     
                                                                                <telerik:GridBoundColumnDataField="Sub2" HeaderText="Sub2" HeaderStyle-Width="100px" UniqueName="Sub2"></telerik:GridBoundColumn>
    </Columns>
    </MasterTableView>
    <ClientSettings AllowKeyboardNavigation="true">
    <ClientEvents  OnRowCreating ="OnRowCreating" />
    </ClientSettings>
    </telerik:RadGrid>

     

    Javascript: 

    function OnRowCreating(sender, args)
    {
    var grid = $find("<%=gvSerialNumberTracking.ClientID %>");
    var MasterTable = grid.get_masterTableView();
    var Rows = MasterTable.get_dataItems();
    var Qty = $("#txtJQuantity").val()
     
    // txtJQuantity is the quantity (in our case its 2)
    if ((Rows.length) > ($("#txtJQuantity").val()))
    {
                                                                         
    //alert('Wait! You cannot add more than ' + $("#txtJQuantity").val() + ' items');
                                                                         
    //args.set_cancel(true);
     
     
    }
    }

     

    Thanks and Regards,

    Sandeep

  2. Eyup
    Admin
    Eyup avatar
    3013 posts

    Posted 21 Apr Link to this post

    Hi Sandeep,

    I am sending a sample RadGrid web site to demonstrate how you can achieve the limiting rows requirement. You can modify the logic to apply the editing implementation.

    Regards,
    Eyup
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sandeep
    Sandeep avatar
    6 posts
    Member since:
    Apr 2016

    Posted 26 Apr in reply to Eyup Link to this post

    hello Eyup,

    i tried the solution give by you but still its not working...

    Problem: when the quantity is more than the number of rows in the grid, the grid is also disappearing along with the button

    i have attached two screen shot .. second pic is the actual grid view

    please check it and let me know

  5. Eyup
    Admin
    Eyup avatar
    3013 posts

    Posted 29 Apr Link to this post

    Hello Sandeep,

    Please open a formal support thread and modify the provided sample to reproduce the described behavior and send it to us.

    Regards,
    Eyup
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  6. Sandeep
    Sandeep avatar
    6 posts
    Member since:
    Apr 2016

    Posted 03 May in reply to Eyup Link to this post

    Hi Eyup...

    i am using below java script to disable the 'Add New button' of batch edit rad-grid when the condition is satisfied.

    Correct the code if its wrong...

    <script type="text/javascript">
    function BatchEditOpening(sender, args)
    {
    var grid = $find("<%=gvSerialNumberTracking.ClientID %>");
    var MasterTable = grid.get_masterTableView();
    var Rows = MasterTable.get_dataItems();
    if ((Rows.length) > ($("#txtJQuantity").val()))
    {
    alert("Wait! you can't enter new records");
    var imageButton = $telerik.findElement(tableView.get_element(), "AddNewRecordButton");
    disableButton(imageButton);
    var linkButton = $telerik.findElement(tableView.get_element(), "InitInsertButton");
    disableButton(linkButton);
    //args.set_cancel(true);
                }
    }
    function disableButton(button) {
    $(button).prop('onclick', null).on("click", function (e) {
    e.preventDefault();
    // alert("Max 4 new records");
    });
    }
    </script>


  7. Eyup
    Admin
    Eyup avatar
    3013 posts

    Posted 06 May Link to this post

    Hi Sandeep,

    I'm glad you've managed to find a solution for your specific scenario.
    If further questions arise, please modify the provided RadGridEditBatchLimitNewRows.zip web site and open a formal support ticket to send it back to us.

    Regards,
    Eyup
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  8. Sandeep
    Sandeep avatar
    6 posts
    Member since:
    Apr 2016

    Posted 06 May in reply to Eyup Link to this post

    hello eyup,

    I am still  facing some problem with the above JQuery so help me in modifing it.

    Thank You

  9. Eyup
    Admin
    Eyup avatar
    3013 posts

    Posted 11 May Link to this post

    Hello Sandeep,

    As suggested in my previous reply, please modify the provided RadGridEditBatchLimitNewRows.zip web site to reproduce the described issue and open a formal support ticket to send it back to us.

    Regards,
    Eyup
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017