RadGrid issue: get_dataItems() not updated after set_dataSource()

7 posts, 0 answers
  1. Sébastien
    Sébastien avatar
    9 posts
    Member since:
    Feb 2009

    Posted 01 Mar 2011 Link to this post

    Hello, I've an issue with client-side databinding of a RadGrid. In fact, when I do a .set_dataSource(<dataSource>) and a .dataBind(), data is successfully loaded in the RadGrid but the length of the property _dataItems doesn't change.

    Here is the code of the RadGrid:
    <Telerik:RadGrid ID="RGWebsites" runat="server" OnNeedDataSource="RGWebsites_NeedDataSource" AllowMultiRowSelection="true" ClientSettings-DataBinding-EnableCaching="false">
        <MasterTableView AutoGenerateColumns="False" DataKeyNames="WebsiteID" ClientDataKeyNames="WebsiteID">
            <Columns>
                <telerik:GridBoundColumn DataField="WebsiteID" HeaderText="Website ID" HeaderStyle-Width="20%" ItemStyle-Width="20%" />
                <telerik:GridBoundColumn DataField="ContractType" HeaderText="Contract type" HeaderStyle-Width="20%" ItemStyle-Width="20%" />
                <telerik:GridBoundColumn DataField="WebsiteName" HeaderText="Website name" HeaderStyle-Width="20%" ItemStyle-Width="20%" />
                <telerik:GridBoundColumn DataField="StartDate" HeaderText="Start date" HeaderStyle-Width="20%" ItemStyle-Width="20%" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}" />
                <telerik:GridBoundColumn DataField="EndDate" HeaderText="End date" HeaderStyle-Width="20%" ItemStyle-Width="20%" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}" />
            </Columns>
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
    </Telerik:RadGrid>

    Here is the code executed in order to load data in the RadGrid:
    function onSuccessGetWebsites(result) {
        if (result && result.Data !== undefined) {
            var tableView = RGWebsites.get_masterTableView();
            tableView.set_dataSource(result.Data);
            tableView.dataBind();
            // By defaut all rows are selected
            tableView.selectAllItems();
            resizeHeight();
        } else {
            if (result.Message) {
                showError(result.Message, 0);
            }
            else {
                showError('onSuccessGetWebsites() result param is empty !', -1);
            }
        }
        $('#' + RGWebsites.get_element().id).unblock();
    };

    Example to explain you more clearly my issue:
    At the first client-side loading, 126 rows are binded in the RadGrid and selected. So the method .get_dataItems() and the method .get_selectedItems() returm 126 items, it's good. But at the second client-side loading, 4 rows are binded in the RadGrid and selected. The grid display 4 rows so it seems to be good again.. but in fact, when I try to do .get_dataItems() or .get_selectedItems() it returns 126 items again! The 4 first items in _dataItems property are the 4 correct items but there're 122 other items (old items).
    I tried to manually delete all items in property _dataItems of the grid but it doesn't work.

    I need to know which items are selected so it's a real problem.

    Thank's for your help.
  2. Sébastien
    Sébastien avatar
    9 posts
    Member since:
    Feb 2009

    Posted 04 Mar 2011 Link to this post

    Up
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kiara
    Kiara avatar
    309 posts
    Member since:
    Jul 2006

    Posted 04 Mar 2011 Link to this post

    Do you get that odd result with the latest release 2010.3.1317 of the telerik ajax controls? I am using it in my app and after a quick debug session of my javascript code I see the the get_dataItems() array is updated accordingly. Not sure whether the version is the problem culprit.

    Kiara
  5. Sébastien
    Sébastien avatar
    9 posts
    Member since:
    Feb 2009

    Posted 07 Mar 2011 Link to this post

    Hi Kiara and thanks for your reply,

    No, I use release 2009.1.402, the problem was probably solved since this release. I will try with a more recent relase.

    Seb
  6. Sébastien
    Sébastien avatar
    9 posts
    Member since:
    Feb 2009

    Posted 07 Mar 2011 Link to this post

    I've tried to upgrade Telerik.Web.UI but unfortunatly Framework .NET 4.0 must be used and I can't change current framework (3.5) due to another DLL.

    Does someone have another solution?

    Thanks, Seb.
  7. Sébastien
    Sébastien avatar
    9 posts
    Member since:
    Feb 2009

    Posted 07 Mar 2011 Link to this post

    I found a solution, if it can help someone who have the same problem:

    function RGWebsites_getSelectedWebsites() {
        var i = 0;
        var dataItems = RGWebsites.get_masterTableView().get_dataItems();
        var selectedWebsitesIDs = new Array();
        for (var i = 0; i < dataItems.length; i++) {
            if (dataItems[i].get_element().style["display"] !== "none" && dataItems[i].get_selected()) { selectedWebsitesIDs.push(dataItems[i].get_dataItem().WebsiteID); }
        }
        return selectedWebsitesIDs;
    }
  8. R
    R avatar
    5 posts
    Member since:
    May 2011

    Posted 11 Jun 2011 Link to this post

    Hi Sébastien, I have the same problem. Can you please tell me what your fix will be doing..

    Thanks


Back to Top
UI for ASP.NET Ajax is Ready for VS 2017