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

How to get the height of an individual row?

2 Answers 181 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 2
Grant asked on 07 Dec 2016, 09:40 PM
I have a RadGrid which can wrap the text in cells.  The end result is that some rows are one line high while others are taller.  How can I determine, server-side, the height of a given row?

2 Answers, 1 is accepted

Sort by
0
Patrick | Technical Support Engineer, Senior
Telerik team
answered on 09 Dec 2016, 09:37 PM
Hi Grant,

Unfortunately, unless you set the height in the code-behind, you will be unable to get the row height from the server-side.  

However, you can get the height client-side using JavaScript.  Here's one approach you can use during the GridCreated event:
<script type="text/javascript">
    function GridCreated(sender, eventArgs) {
        var masterTable = sender.get_masterTableView();
        var count = masterTable.get_dataItems().length;
        for (var i = 0; i < count; i++) {
            let item = masterTable.get_dataItems()[i];
            console.log("Row " + i + " height = " + item.get_element().clientHeight);
        }
    }
</script>

I've attached a project which uses the approach above.

I hope this helps!

Regards,
Patrick
Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
0
Grant
Top achievements
Rank 2
answered on 09 Dec 2016, 10:00 PM

Thanks Patrick.  I wasn't sure if it was possible to get the height of an autosized row server side but feared that wasn't gonna happen.

I ended up setting the height server side so that two rows of text would show.  It's a little tall if there's only one row of text but it's not too bad.

Tags
Grid
Asked by
Grant
Top achievements
Rank 2
Answers by
Patrick | Technical Support Engineer, Senior
Telerik team
Grant
Top achievements
Rank 2
Share this question
or