Почему высота таблицы возвращается 0 - PullRequest
1 голос
/ 15 января 2020

После того, как я добавлю элемент tr в таблицу. Я хочу прокрутить до этого tr. Поэтому мне нужно получить значение tr, но оно всегда возвращает 0. Пожалуйста, помогите мне.

Мой код указан ниже:

$('#desk_customerlister table tbody tr.selected').removeClass('selected');
$('#desk_customerlister table tbody').append("<tr class='selected'><th></th><td class='invisible-cell' id='IsDeleted'>false</td><td class='invisible-cell' id='IsEdited'>false</td><td class='invisible-cell' id='Id'>" + obj.Id + "</td><td id='Code'>" + row.Code + "</td><td id='Name'>" + row.Name + "</td><td id='Address'>" + row.Address + "</td><td id='Contact'>" + row.Contact + "</td><td id='Phone'>" + row.Phone + "</td><td id='Email'>" + row.Email + "</td><td class='invisible-cell' id='CreatedAt'>" + obj.ModifiedAt + "</td><td class='invisible-cell' id='CreatedBy'>" + row.UserName + "</td><td class='invisible-cell' id='ModifiedAt'>" + obj.ModifiedAt + "</td><td class='invisible-cell' id='ModifiedBy'>" + row.UserName + "</td></tr>");

var lastrow = $('#desk_customerlister table tbody tr.selected:first');

console.log('Height = ' + lastrow.height());

$('#desk_customerlister').scrollTop((lastrow.index() + 1) * lastrow.height() - $('#desk_customerlister').height() + $('#desk_customerlister thead').height());

1 Ответ

0 голосов
/ 15 января 2020

Я нашел ответ, который вы можете сделать после того, как html готов:

$('#desk_customerlister table tbody tr.selected').removeClass('selected');
$('#desk_customerlister table tbody').append("<tr class='selected'><th></th><td class='invisible-cell' id='IsDeleted'>false</td><td class='invisible-cell' id='IsEdited'>false</td><td class='invisible-cell' id='Id'>" + obj.Id + "</td><td id='Code'>" + row.Code + "</td><td id='Name'>" + row.Name + "</td><td id='Address'>" + row.Address + "</td><td id='Contact'>" + row.Contact + "</td><td id='Phone'>" + row.Phone + "</td><td id='Email'>" + row.Email + "</td><td class='invisible-cell' id='CreatedAt'>" + obj.ModifiedAt + "</td><td class='invisible-cell' id='CreatedBy'>" + row.UserName + "</td><td class='invisible-cell' id='ModifiedAt'>" + obj.ModifiedAt + "</td><td class='invisible-cell' id='ModifiedBy'>" + row.UserName + "</td></tr>");

var lastrow = $('#desk_customerlister table tbody tr.selected:first');

$(function() {
	console.log('Height = ' + lastrow.height());
	$('#desk_customerlister').scrollTop((lastrow.index() + 1) * lastrow.height() - $('#desk_customerlister').height() + $('#desk_customerlister thead').height());
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...