How to get the height of an individual row?

3 posts, 0 answers
  1. Grant
    Grant avatar
    4 posts
    Member since:
    Jul 2012

    Posted 07 Dec 2016 Link to this post

    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. Patrick
    Admin
    Patrick avatar
    207 posts

    Posted 09 Dec 2016 Link to this post

    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.
  3. Grant
    Grant avatar
    4 posts
    Member since:
    Jul 2012

    Posted 09 Dec 2016 Link to this post

    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.

Back to Top