CalculatedColumn In Batch Editing

8 posts, 1 answers
  1. Jason
    Jason avatar
    9 posts
    Member since:
    Sep 2013

    Posted 01 Sep 2013 Link to this post

    I'd like know how to use CalculatedColumn in Batch Editing mode. The most common scenario is UnitPrice * Quantity = Total Price. 

    CalculatedColumn works fine in first inquiry. But when grid in Batch Editing mode, the Calculated Column in Client side has no mechanism to  automatically calculate.  I try to update total price cell  by java code, but I found there is no way to find the element. 

    Please kindly help me to implement this. 

    With best regards

    Jason
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Sep 2013 Link to this post

    Hi Jason,

    Please try the following code snippet.I was able to get the changes made to the columns be reflected on the calculated column automatically when the values are changed and saved.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
        GridLines="None" AllowPaging="true" ShowFooter="true" AllowAutomaticDeletes="true"
        AllowAutomaticInserts="true" AllowAutomaticUpdates="true">
        <MasterTableView DataKeyNames="OrderID" EditMode="Batch" CommandItemDisplay="Top">
            <Columns>
                <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />
                <telerik:GridBoundColumn UniqueName="ProductID" DataField="ProductID" HeaderText="ProductID" />
                <telerik:GridBoundColumn DataField="UnitPrice" HeaderText="UnitPrice" UniqueName="UnitPrice" />
                <telerik:GridBoundColumn DataField="Quantity" HeaderText="Quantity" UniqueName="Quantity" />
                <telerik:GridBoundColumn DataField="Discount" HeaderText="Discount" UniqueName="Discount" />
                <telerik:GridCalculatedColumn HeaderText="Total" UniqueName="TotalPrice" DataType="System.Double"
                    DataFields="UnitPrice, Quantity" Expression="{0}*{1}" FooterText="Total : " Aggregate="Sum">
                </telerik:GridCalculatedColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>"
        DeleteCommand="DELETE FROM [Order details] WHERE [OrderID] = @OrderID" InsertCommand="INSERT INTO [Order details] ([OrderID],[UnitPrice], [Quantity],[ProductID],[Discount]) VALUES (@OrderID, @UnitPrice, @Quantity,@ProductID,@Discount)"
        SelectCommand="SELECT [OrderID], [UnitPrice],  [Quantity],[ProductID],[Discount] FROM [Order details] "
        UpdateCommand="UPDATE [Order details] SET [UnitPrice] = @UnitPrice,  [Quantity] = @Quantity,[ProductID]=@ProductID,[Discount]=@Discount WHERE [OrderID] = @OrderID">
        <DeleteParameters>
            <asp:Parameter Name="OrderID" Type="Int32"></asp:Parameter>
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="OrderID"></asp:Parameter>
            <asp:Parameter Name="ProductID"></asp:Parameter>
            <asp:Parameter Name="UnitPrice"></asp:Parameter>
            <asp:Parameter Name="Quantity"></asp:Parameter>
            <asp:Parameter Name="Discount"></asp:Parameter>
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="OrderID" Type="Int32"></asp:Parameter>
            <asp:Parameter Name="ProductID"></asp:Parameter>
            <asp:Parameter Name="UnitPrice"></asp:Parameter>
            <asp:Parameter Name="Quantity"></asp:Parameter>
            <asp:Parameter Name="Discount"></asp:Parameter>
        </UpdateParameters>
    </asp:SqlDataSource>

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jason
    Jason avatar
    9 posts
    Member since:
    Sep 2013

    Posted 02 Sep 2013 Link to this post

    Dear Princy

    thank you for your help. it seems by your code, the calculated column only has been updated after saved,  can I get it updated in client side before saved? so the customer can review the total price before saved.

    I intercept the client events   OnBatchEditSetCellValue="SetCellValue"

    but in SetCellValue , I couldn't find the cell of "Total Price"

     

    function SetCellValue(sender, args) {
                if (args.get_columnUniqueName() === "Quantity" || args.get_columnUniqueName() === "UnitPrice") {
      
                    
                    var row = args.get_row();
                    var tableview = args.get_tableView();
                      
                    alert(row.get_cell("TotalPrice").innerText);
                   // var cell = tableview.getCellByColumnUniqueName(row, "UnitPrice");
                    //alert(cell.innerHTML);
      
                }

    I'd tried many ways to get the cell, above code is failure on get total price cell. Is there any API document for these functions?

    PS: I don't need update total price to db, like your code. I just want the interface friendly.

    thank you very much.

    With best regards

    Jason


  5. Answer
    Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 04 Sep 2013 Link to this post

    Hello Jason,

    I am sorry to say but the current implementation of the batch editing functionality does not support modifying the value in the calculated column before an update in the database. However you could log this as a feature request in our feedback portal and if it gets popular enough we might consider including it in a future release.

    For now this is achievable by manually calculating the value and placing it in the HTML. A sample demonstration on how to achieve this can be observed in the attached website.

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Jason
    Jason avatar
    9 posts
    Member since:
    Sep 2013

    Posted 04 Sep 2013 Link to this post

    Dear Angel

    Thank you for your help.  This demo helps a lot.

    Meanwhile, align attributions are missing from new row inserted in Batch Editing mode.

  7. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 09 Sep 2013 Link to this post

    Hello Jason,

    Do you mean that the editors in the new records are not aligned properly? The was such an issue when some of the columns were hidden by setting Display="False". However this problem is already fixed and if you download the latest internal build you should not experience such behavior.

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  8. Ashraf Sabry
    Ashraf Sabry avatar
    88 posts
    Member since:
    Jan 2011

    Posted 25 Nov 2013 Link to this post

    Greetings,

    My company business requires this feature too. In fact, I'm currently writing a general solution to this problem.
    Was this feature requested on the feedback portal? If so, please provide me with the issue link to upvote it.
  9. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 28 Nov 2013 Link to this post

    Hi Ashraf,

    I researched our feedback portal but was unable to find a feature request for the mentioned functionality. For now you can follow the approach demonstrated in the below attached project.

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017