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

[Solved] Fixed grid height

1 Answer 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tawit
Top achievements
Rank 1
Tawit asked on 24 Nov 2011, 09:26 AM
How can i fixed grid height?

I want to show maximum row per page is 10 rows.
But if the data has only 5 rows, i want to show 5 rows data and 5 empty rows.
Total are 10 rows, Can i do this?

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 24 Nov 2011, 11:17 AM
Hello Tawit,

You need to subscribe to the OnDataBound event if Ajax binding is used, and to OnLoad if server binding is used.

Html.Telerik().Grid().ClientEvents(ev => ev.OnDataBound("addEmptyRows"))

Then you should count how many data rows you have and append as much empty rows as needed. The number of columns must be taken into account.

The Javascript code should do this if scrolling is enabled:

function addEmptyRows(e)
{
    var dataTable = $(".t-grid-content table", this);
    var rows = $("tr", dataTable).not(".t-no-data");
    var rowsCount = rows.length;
    var pageSize = 20;
    var difference = pageSize - rowsCount;
    var columnCount = $(this).data("tGrid").columns.length;
    if (rowsCount > 0 && difference > 0) {
        var rowClasses = [];
        rowClasses[0] = $(rows[rows.length - 1]).hasClass("t-alt") ? "" : "t-alt";
        rowClasses[1] = rowClasses[0] == "t-alt" ? "" : "t-alt";
         
        for (var j = 0; j < difference; j++) {
            var str = "";
            str += '<tr class="' + rowClasses[ j % 2] + '">';
            for (var k = 0; k < columnCount; k++) {
                str += "<td> </td>";
            }
            str += "</tr>";
            $(str).appendTo(dataTable);
        }
    }
}


The dataTable selector should be changed to the following if scrolling is not enabled:

var dataTable = $("> table > tbody", this);


Greetings,
Dimo
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Tawit
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or