Getting radgrid first, to be inserted dataitem on client

7 posts, 0 answers
  1. Zinoviy Margovskiy
    Zinoviy Margovskiy avatar
    28 posts
    Member since:
    Mar 2009

    Posted 08 Jul 2010 Link to this post

    HI,

    I need to traverse through radgrid dataitems on client to perform some logic.  It looks like my code works fine in readonly and update mode, however it does not work when
    I am trying to insert any item in the grid.  Basically I do not know how to get reference to the "to be inserted item".

    For example, if I am inserting first item in the grid then
    masterTableView.get_dataItems().length returns 0.
    So the Question is:
    1. how do I reference the "To be inserted item"
    2. how do I get a reference an element/control inside "To be inserted item")
    Please Help...

    Here is my javascript function:
    function getTaxableOrderSubTotal()
    {
         
        var taxableOrderSubTotalAmnt = 0.00;
        var radGrid = $find('<%= RadGrid1.ClientID %>');
        var masterTableView;
        var tableViewRows;
        var length = 0;
     
        if (radGrid) {
            masterTableView = radGrid.get_masterTableView();
        }
        if (masterTableView) {
            tableViewRows = masterTableView.get_dataItems();
        }
     
        if (tableViewRows) {
            length = tableViewRows.length;
        }
     
        if (masterTableView) {
            if (length > 0) {
                for (var i = 0; i < length; i++) {
                    var dataItem = masterTableView.get_dataItems()[i];
                    var isLITaxable = false;
     
                    if (dataItem) {
                        // 1. Get Taxable Check box value
                        var chkTxbl = dataItem.findElement("chkTaxableLI");
                        var liTotalPrice = 0.00;
     
                        if (chkTxbl && chkTxbl.checked) {
     
                            // Get Total lineITem Price:
                            // if litTotalPrice control is found the
                            //item is in readonly mode
                            // if txtTotalPrice control is found then
                            // item is in edit mode
                            if (dataItem.findElement("litTotalPrice")) {
                                liTotalPrice = dataItem.findElement("litTotalPrice").value;
                            }
                            else if (dataItem.findElement("txtTotalPrice")) {
                                liTotalPrice = dataItem.findElement("txtTotalPrice").value;
                            }
     
                            taxableOrderSubTotalAmnt = parseFloat(taxableOrderSubTotalAmnt) + parseFloat(liTotalPrice);
                        }
                    }
                }
            }

        }
     
        return taxableOrderSubTotalAmnt;
    }
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 13 Jul 2010 Link to this post

    Hi Zinoviy,

    Below is the code which detects the insert/edit mode respectively:
    <script type="text/javascript">   
                            
                       function gridCreated(sender, args)   
                       {   
                       var RadGrid = $find("<%=Grid1.ClientID %>");   
                       alert("Inserting:" + RadGrid.get_masterTableView().get_isItemInserted());   
                       alert("editItems:" + RadGrid._editIndexes.length);   
                       }   
                      
               </script>

    <ClientEvents OnGridCreated="gridCreated" />

    Let me know if it helps to achieve your goal or if I am leaving something out.

    Regards,
    Pavlina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Zinoviy Margovskiy
    Zinoviy Margovskiy avatar
    28 posts
    Member since:
    Mar 2009

    Posted 13 Jul 2010 Link to this post

    Pavlina,
    Thank you for your reply, however, you showed me how to figure out which mode (edit/insert) a radgrid is in;
    but my two questions were:

    1. how do I reference the "To be inserted item" and
    2. how do I get a reference an element/control inside "To be inserted item")

    Let's say I have a grid with three columns:
    Price ==> with EditItemTemplate having RadNumericTextBox control
    Taxable ==> with EditItemTemplate having check box control
    Total Price ==> with EditItemTemplate having RadNumericTextBox control

    Lets say also I have Two RadNumericTextBoxes outside of the grid: Tax Percent and Total Tax amount.
    Once Tax percent is modified I'd like to calculate total tax amount based on Prices entered in the Grid and whether "Taxable"
    Check box is checked for any given grid row.  I'd like to be able to do these calculations on client (inside JavaScript)
    This is relatively easy to do when radgrid is in "edit" or "read-only" mode (see posted code), since we have reference to dataItem object:
    masterTableView.get_dataItems()
    But when radGrid is in insert mode, my understanding is that dataItem for "to be inserted row" is not available in current grid APIs.

    Therefore, I have those two questions specified above.
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 16 Jul 2010 Link to this post

    Hi Zinoviy,

    I would like to ask you to open a support ticket and send me a small sample project that shows your exact setup. Once I have a better view over your exact scenario, I will do my best to provide you with the most appropriate solution.

    Greetings,
    Pavlina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 02 Jun 2011 Link to this post

    Was there any solution to this?
  7. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 03 Jun 2011 Link to this post

    Hello Jeremy,

    As I said in my previous post I need a sample project in order to have a better view over your exact scenario.
    Thus I will be able to check it and get back to you with a solution.

    Thank you for your cooperation.

    Greetings,
    Pavlina
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  8. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 06 Jun 2011 Link to this post

    So I assume Zinoviy never supplied a sample project or opened a ticket?
    For anyone else who needs help, here is how I did it. I'm not happy about hardcoding the checkbox control's index, but it works :)

    function SelectInsertCheckBox(gridid,condition) {
       var grid = $find(gridid);
       //check if in insert mode
       if (grid.get_masterTableView().get_isItemInserted() == true) {
          // get checkbox
          var chkinsert = grid.get_element().getElementsByClassName("rgEditRow")[0].getElementsByTagName("input")[3];
          if (condition == true) {
             chkinsert.checked = true;
          }
          else {
             chkinsert.checked = false;
          }
       }
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017