This is a migrated thread and some comments may be shown as answers.

Problem while restricting Add new Record button in RadGrid

7 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sandeep
Top achievements
Rank 1
Sandeep asked on 18 Apr 2016, 02:00 PM

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

7 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 21 Apr 2016, 10:49 AM
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.
0
Sandeep
Top achievements
Rank 1
answered on 26 Apr 2016, 10:53 AM

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

0
Eyup
Telerik team
answered on 29 Apr 2016, 05:57 AM
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.
0
Sandeep
Top achievements
Rank 1
answered on 03 May 2016, 07:38 AM

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>


0
Eyup
Telerik team
answered on 06 May 2016, 05:34 AM
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.
0
Sandeep
Top achievements
Rank 1
answered on 06 May 2016, 08:57 AM

hello eyup,

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

Thank You

0
Eyup
Telerik team
answered on 11 May 2016, 05:49 AM
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.
Tags
Grid
Asked by
Sandeep
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Sandeep
Top achievements
Rank 1
Share this question
or