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

Radgrid batcheditor not working

1 Answer 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nagarajan
Top achievements
Rank 2
Nagarajan asked on 18 Jul 2016, 08:09 AM

Hi,

I am validation duplicate records in radgrid batch edit in client side.

When initial grid, if duplicate date available means shows message after deleting the duplicate records, we are not able to get cell values in batchedit

Details given below

Clent side code
<telerik:RadGrid ID="grdBillDetails" runat="server"
                    OnBatchEditCommand="grdBillDetails_BatchEditCommand"
                    AutoGenerateColumns="false"
                    OnNeedDataSource="grdBillDetails_NeedDataSource"
                    ClientSettings-Scrolling-AllowScroll="true"
                    Visible="true" ShowFooter="true"
                    ClientSettings-Scrolling-UseStaticHeaders="true"
                    ClientSettings-ClientEvents-OnBatchEditOpening="BeforeEdit"
                    OnPreRender="grdBillDetails_PreRender">

                    <MasterTableView DataKeyNames="billno,billdt,pharmacyname,amount" GridLines="None" HeaderStyle-Font-Bold="true" HeaderStyle-Wrap="false" ItemStyle-Wrap="true" CommandItemDisplay="Top"
                        EditMode="Batch" BatchEditingSettings-EditType="Row" ItemStyle-VerticalAlign="Top">
                        <Columns>
                            <telerik:GridTemplateColumn ItemStyle-Width="25px" HeaderStyle-Width="25px">
                                <ItemTemplate>
                                    <textarea class="pasteHandle" contenteditable="true" onmousedown="this.innerText = ''; this.focus(); return false;" onmouseover="    this.focus(); return false;" oncontextmenu="    this.innerText = ''; return false;"></textarea>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <textarea class="pasteHandle" contenteditable="true" onmousedown="this.innerText = ''; this.focus(); return false;" onmouseover="    this.focus(); return false;" oncontextmenu="    this.innerText = ''; return false;"></textarea>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="billno" HeaderText="Bill No" HeaderStyle-Width="150px" UniqueName="billno">
                                <ItemTemplate>
                                    <%# Eval("billno")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadTextBox ID="txtBillNo" runat="server" Width="100px"></telerik:RadTextBox><asp:RequiredFieldValidator CssClass="rfv" runat="server" ID="rfvbillno" Display="Dynamic" ControlToValidate="txtBillNo"
                                        SetFocusOnError="true" ErrorMessage="Bill No Mandatory" ValidationGroup="Medical"></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="billdt" HeaderText="Bill Date" HeaderStyle-Width="200px" UniqueName="billdt">
                                <ItemTemplate>
                                    <%# Eval("billdt", "{0:dd/MM/yyyy}") %>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadDatePicker ID="txtBillDate" runat="server" Width="150px">
                                        <DateInput runat="server" DateFormat="dd/MM/yyyy" DisplayDateFormat="dd/MM/yyyy" />
                                        <Calendar runat="server">
                                            <SpecialDays>
                                                <telerik:RadCalendarDay Repeatable="Today" ItemStyle-BackColor="Olive">
</telerik:RadCalendarDay>
                                            </SpecialDays>
                                        </Calendar>
                                    </telerik:RadDatePicker>
                                    <asp:RequiredFieldValidator CssClass="rfv" runat="server" ID="rfvbillDate" Display="Dynamic" ControlToValidate="txtBillDate"
                                        SetFocusOnError="true" ErrorMessage="Bill Date Mandatory" ValidationGroup="Medical"></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="pharmacyname" HeaderText="Pharmacy/Doctor Name" HeaderStyle-Width="450px" UniqueName="pharmacyname">
                                <ItemTemplate>
                                    <%# Eval("pharmacyname")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadTextBox ID="txtPharmacyName" runat="server" Width="400px" MaxLength="100">
                                        </telerik:RadTextBox>
<asp:RequiredFieldValidator CssClass="rfv" runat="server" ID="rfvPharmacy" Display="Dynamic" ControlToValidate="txtPharmacyName" SetFocusOnError="true" ErrorMessage="Pharmacy Mandatory" ValidationGroup="Medical"></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="amount" HeaderText="Bill Amount" FooterAggregateFormatString="{0}" FooterStyle-Font-Bold="true" Aggregate="Sum" UniqueName="amount">
                                <ItemTemplate>
                                    <%# Eval("amount")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadNumericTextBox ID="txtBillAmount" runat="server" Width="100px" MaxLength="10">
                                        <NumberFormat DecimalDigits="2" AllowRounding="true" />
<ClientEvents OnKeyPress="preventMoreDecimalPlaces" />
                                    </telerik:RadNumericTextBox>
                                    <asp:RequiredFieldValidator CssClass="rfv" runat="server" ID="rfvAmount" Display="Dynamic" ControlToValidate="txtBillAmount" SetFocusOnError="true" ErrorMessage="Amount Mandatory" ValidationGroup="Medical">   </asp:RequiredFieldValidator>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridButtonColumn HeaderStyle-Width="100px" ButtonType="ImageButton" ImageUrl="../../Resources/Images/cross.png"
                                ButtonCssClass="rbEdit" UniqueName="DeleteColumn" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                                CommandName="Delete" HeaderText="Delete">
                            </telerik:GridButtonColumn>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings>
                        <ClientEvents OnCommand="grdBillDetails_OnCommand"                           
                            OnRowDeleted="grdBillDetails_OnRowDeleted"
                            OnBatchEditClosed="grdBillDetails_OnBatchEditClosed"
                             />
                    </ClientSettings>
                </telerik:RadGrid>

function grdBillDetails_OnCommand(sender, args) {
                var grdbilldetails = $find("<%=grdBillDetails.ClientID %>");
                var masterTable = grdbilldetails.get_masterTableView();
                var dts = masterTable.get_dataItems();
                for (var i = 0; i < dts.length - 1; i++) {
                    var prevbillno = grdbilldetails.get_batchEditingManager().getCellValue(dts[i].get_cell("billno"));
                    var prevbilldt = grdbilldetails.get_batchEditingManager().getCellValue(dts[i].get_cell("billdt"));
                    var prevpharmacyname = grdbilldetails.get_batchEditingManager().getCellValue(dts[i].get_cell("pharmacyname"));
                    for (var j = i + 1; j < dts.length; j++) {
                        curbillno = grdbilldetails.get_batchEditingManager().getCellValue(dts[j].get_cell("billno"));
                        curbilldt = grdbilldetails.get_batchEditingManager().getCellValue(dts[j].get_cell("billdt"));
                        curpharmacyname = grdbilldetails.get_batchEditingManager().getCellValue(dts[j].get_cell("pharmacyname"));
if (prevbillno == curbillno && prevbilldt == curbilldt && prevpharmacyname == curpharmacyname) {
                            alert('Duplicates data available for Same BillNo,Billdate,Pharmacy');
                            grdbilldetails.get_batchEditingManager().openCellForEdit(dts[j].get_cell("billno"));
                            args.set_cancel(true);
                            return false;
                        }

                    }
                }
}

Server Side
foreach (GridBatchEditingCommand command in e.Commands)
                {
                    DataRow resultRw = resultDt.NewRow();

                    if (command.Type == GridBatchEditingCommandType.Insert)
                    {

                        resultRw["BillNo"] = command.NewValues["billno"];
                        resultRw["BillDate"] = command.NewValues["billdt"];
                        resultRw["Pharmacy"] = command.NewValues["pharmacyname"];
                        resultRw["BillValue"] = command.NewValues["amount"];
                        resultRw["Ind"] = "I";

                    }

                    if (command.Type == GridBatchEditingCommandType.Update)
                    {

                            resultRw["BillNo"] = command.NewValues["billno"];
                            resultRw["BillDate"] = command.NewValues["billdt"];
                            resultRw["Pharmacy"] = command.NewValues["pharmacyname"];
                            resultRw["BillValue"] = command.NewValues["amount"];
                            resultRw["Ind"] = "U";


                    }

                    if (command.Type == GridBatchEditingCommandType.Delete)
                    {
                            resultRw["BillNo"] = command.NewValues["billno"];
                            resultRw["BillDate"] = command.NewValues["billdt"];
                            resultRw["Pharmacy"] = command.NewValues["pharmacyname"];
                            resultRw["BillValue"] = command.NewValues["amount"];
                            resultRw["Ind"] = "D";

                    }

                    resultDt.Rows.Add(resultRw);

                }
Screen shots
In grid Duplicate data available. So it shows error.





After getting duplicate row deletion. Unable to get the grid datas.

Thanks in advance

 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 21 Jul 2016, 05:34 AM
Hello Nagarajan,

I have tested the scenario in question with our latest version and the NewValues collection holds the original values of the item that was deleted and this is the expected behavior, because they are the actual values of the item that should be deleted. 

If you have something different in mind, please provide some additional information on your requirement and the exact issue that you are facing. 

Meanwhile you can try using the OldValues collection and see if those values will be present in it.


Regards,
Konstantin Dikov
Telerik by Progress
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
Nagarajan
Top achievements
Rank 2
Answers by
Konstantin Dikov
Telerik team
Share this question
or