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

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

6 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sébastien
Top achievements
Rank 1
Sébastien asked on 01 Mar 2011, 05:13 PM
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.

6 Answers, 1 is accepted

Sort by
0
Sébastien
Top achievements
Rank 1
answered on 04 Mar 2011, 08:52 AM
Up
0
Kiara
Top achievements
Rank 1
answered on 04 Mar 2011, 02:42 PM
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
0
Sébastien
Top achievements
Rank 1
answered on 07 Mar 2011, 09:46 AM
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
0
Sébastien
Top achievements
Rank 1
answered on 07 Mar 2011, 09:59 AM
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.
0
Sébastien
Top achievements
Rank 1
answered on 07 Mar 2011, 02:33 PM
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;
}
0
R
Top achievements
Rank 1
answered on 12 Jun 2011, 04:50 AM
Hi Sébastien, I have the same problem. Can you please tell me what your fix will be doing..

Thanks


Tags
Grid
Asked by
Sébastien
Top achievements
Rank 1
Answers by
Sébastien
Top achievements
Rank 1
Kiara
Top achievements
Rank 1
R
Top achievements
Rank 1
Share this question
or