如何使用Datatables行偏移量对此jquery进行计算

时间:2019-01-10 22:25:24

标签: javascript jquery html css

我的JavaScript代码是:

var selectedRow = $('#tblCompany tbody tr').eq(index);
$('.dataTables_scrollBody').scrollTop(selectedRow.prop('offsetTop') - $('.dataTables_scrollBody').height() / 2)

$('.dataTables_scrollBody').height()       // is set to 300 px
$('.dataTables_scrollBody').height() / 2)  // 300 / 2 = 150

当我这样做时:

  • 对于第0行,selectedRow.prop('offsetTop')报告:0
  • 第16行:selectedRow.prop('offsetTop')报告:509

我想了解这个509是如何计算的,是从asp.net表单的顶部吗?还是从tblCompany表的顶部开始?

这是HTML页面:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<body style="font-family: Century Gothic; font-size: 12px;">
  <form id="form1" runat="server">

    <h3>
      <asp:Label runat="server" ID="lbltopmsg" Text="&nbsp;&nbsp; Data is being loaded.. Please wait several seconds" Font-Bold="True"></asp:Label>
    </h3>

    <table id="tblJquery" align="center" runat="server" width="80%">

      <tr>
        <td>
          <div id="divtop" style="width: 80%; border: 1px solid black; padding: 3px">

            <table id="tblCompany" border="0" class="cell-border compact stripe" style="border-collapse: collapse; font-size: medium">
              <thead>
                <tr>
                  <th id="thcompany">CompanyRecordID</th>
                  <th>PermitNumberSuffix</th>
                  <th>CompanyName</th>
                  <th>City</th>
                  <th>Issue&nbsp;Date</th>
                  <th>Action</th>

                </tr>
              </thead>

              <tbody></tbody>

              <tfoot>
                <tr>
                  <th>CompanyRecordID</th>
                  <th>PermitNumberSuffix</th>
                  <th>CompanyName</th>
                  <th>City</th>
                  <th>Issue&nbsp;Date</th>
                  <th>Action</th>

                </tr>

              </tfoot>
            </table>


          </div>
        </td>
      </tr>
    </table>
  </form>
</body>

0 个答案:

没有答案