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

[Solved] get_display() always returns false

4 Answers 283 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave Myers
Top achievements
Rank 1
Dave Myers asked on 16 Nov 2009, 04:25 PM
I am trying to get the visibility of a datagrid row and it always returns "false".
function toggleTreeRows(gridId,rowId) { 
        var masterTable = $find(gridId).get_masterTableView(); 
        var rows = masterTable.get_dataItems(); 
        for (var i = 0; i < rows.length; i++){ 
            var row = rows[i]; 
             
            if (rowId == row.get_element().getAttribute('lineage')){ 
                alert(row.get_display()); 
                break
            } 
        } 
    } 


any ideas?

4 Answers, 1 is accepted

Sort by
0
Dave Myers
Top achievements
Rank 1
answered on 16 Nov 2009, 04:32 PM
one thing i also noticed that after the initial page load, the first time calling the function results in an error where the $find function returns null for the grid.  Subsequent calls to the function do not produce the error.  Another curious thing is that I can call hideItem() and it works.

Help, I need to get this working.
0
Johny
Top achievements
Rank 1
answered on 17 Nov 2009, 02:27 PM
Hi Dave,

Have you tried whether the following make any difference:

alert(row.get_visible());  

As to the error on the initial load can you please specify on which event you call your function?

I hope this helps
Johny


0
Dave Myers
Top achievements
Rank 1
answered on 17 Nov 2009, 02:32 PM
calling get_visible() always returns true.

With the initial load issue, the sequence is:
1) page loads completely
2) click button that calls toggleTreeRow()
3) nothing happens, but javascript error console that the $find(gridId) is null causeing the function to fail
4) click button that calls toggleTreeRow() again
5) no errors reported, but get_display() always returns false.
0
Martin
Telerik team
answered on 20 Nov 2009, 09:05 AM
Hello Dave,

Could you please try the following code and let me know of the result you get:

<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript">
        function ClientClick(sender, args)
        {
            var grid = $find("<%=RadGrid1.ClientID %>")
            var masterTable = grid.get_masterTableView();
            var rows = masterTable.get_dataItems();
            for (var i = 0; i < rows.length; i++)
            {
                var row = rows[i];
                alert("ROW " + i + " is visible: " + row.get_visible());
            }
        }
    </script>
  
    <div>
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="True" OnNeedDataSource="RadGrid1_NeedDataSource"
            OnItemCreated="RadGrid1_ItemCreated">
        </telerik:RadGrid>
        <asp:Button runat="server" OnClientClick="ClientClick();return false;" Text="Get items visibility" />
    </div>


Here is the code behind:

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("Column1");
        table.Columns.Add("Column2");
        table.Columns.Add("Column3");
        for (int i = 0; i < 3; i++)
        {
            table.Rows.Add("Column1 ROW " + i, "Column2 ROW " + i, "Column3 ROW " + i);
        }
        RadGrid1.DataSource = table;
    }
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem && e.Item.ItemIndex == 1)
        {
            e.Item.Display = false;
        }
    }

Regards,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Dave Myers
Top achievements
Rank 1
Answers by
Dave Myers
Top achievements
Rank 1
Johny
Top achievements
Rank 1
Martin
Telerik team
Share this question
or