1

私はしばらくの間この問題と戦ってきました。jQuery DataTableの幅は、画面のサイズを変更した後にのみ正しく表示されます。このスクリーンキャストを見て、何が起こるかを確認してください。

http://screencast.com/t/QY2ZgZp4By

シナリオは次のとおりです。

ASP.NETを使用して、CSVファイルからデータをインポートし、動的にテーブルを作成します。ファイルには可変数の列があるため、任意の数の列にすることができます。

テーブルを作成した後、DataTableスクリプトを呼び出して、以下に示すようにテーブルをフォーマットします。

        Private Sub CreateInputDataTable()

        Dim input As BA.Input = CurrentInput
        Dim inputLines As BA.InputLines = input.Lines
        Dim columnHeaders As BA.InputColumnHeaders = input.ColumnHeaders
        'Dim loadDefItems As BA.InputLoadDefinitionItems = CurrentInputLoadDefinition.DefinitionItems

        phInputLoadData.Controls.Clear()

        Dim tblRows As Integer = inputLines.Count
        Dim tblCols As Integer = 19 ' Hard coded col number to create sample
        ' Create a Table and set its properties 
        Dim tbl As Table = New Table()
        ' Add the table to the placeholder control

        tbl.ID = "tblInputLoad"
        tbl.Attributes.Add("runat", "server")
        tbl.Width = Unit.Percentage(100)

        phInputLoadData.Controls.Add(tbl)

        'Add dropdown boxes to row headers
        Dim thr As TableHeaderRow = New TableHeaderRow()
        thr.TableSection = TableRowSection.TableHeader

        For i As Integer = 0 To tblCols - 1
            Dim cboColName As DropDownList = New DropDownList()

            Dim thc As TableHeaderCell = New TableHeaderCell()
            thc.Width = Unit.Pixel(80)

            thc.CssClass = "input-def-col-header"

            With cboColName
                .ID = "cboColName_" + i.ToString()
                .Width = Unit.Pixel(80)

                AddHandler cboColName.PreRender, AddressOf cboColName_PreRender

            End With

            'Add control to the table cell
            thc.Controls.Add(cboColName)

            'Add table cell to the TableRow
            thr.Cells.Add(thc)
        Next

        tbl.Rows.Add(thr)

        ' Add column headers
        thr = New TableHeaderRow()
        thr.TableSection = TableRowSection.TableHeader

        For i As Integer = 0 To tblCols - 1
            Dim thc As TableHeaderCell = New TableHeaderCell()
            thc.Width = Unit.Pixel(80)
            Dim txtBox As TextBox = New TextBox()

            txtBox.CssClass = "input-file-col-header"
            txtBox.Text = columnHeaders(i).ColumnHeaderName
            txtBox.Width = Unit.Pixel(80)
            ' Add the control to the TableCell
            thc.Controls.Add(txtBox)
            ' Add the TableCell to the TableRow
            thr.Cells.Add(thc)
        Next

        tbl.Rows.Add(thr)

        Dim tr As TableRow = New TableRow
        tr.TableSection = TableRowSection.TableBody

        ' Now iterate through input lines and add controls 
        For i As Integer = 0 To tblRows - 1
            tr = New TableRow()

            For j As Integer = 0 To tblCols - 1
                Dim tc As TableCell = New TableCell()
                tc.Width = Unit.Pixel(80)
                Dim txtBox As TextBox = New TextBox()
                txtBox.Width = Unit.Pixel(80)
                txtBox.Text = inputLines(i).Items(j).Value

                If inputLines(i).Items(j).ItemType <> BudgetAllocations.InputDefinitionColumnType.Data Then
                    txtBox.CssClass = "input-file-frozen-left-cols"
                End If

                ' Add the control to the TableCell
                tc.Controls.Add(txtBox)
                ' Add the TableCell to the TableRow
                tr.Cells.Add(tc)
            Next j

            ' Add the TableRow to the Table
            tbl.Rows.Add(tr)
        Next i

        ClientScript.RegisterClientScriptBlock(Me.GetType(), "FormatInputTable", _
              "$(document).ready(function() {FormatInputTable();});", True)

    End Sub

以下に示すように、テーブルはASP.NETプレースホルダーに挿入されます。

  <div id="div-input-load-cont" style="float: left; width: 70%; margin-top: 5px; height: 350px">
    <asp:PlaceHolder ID="phInputLoadData" runat="server" EnableViewState="False"></asp:PlaceHolder>
  </div>

そして、これがテーブルをフォーマットするためのスクリプトです:

    function FormatInputTable() {
  var oTable = $('#ctl00_MainContent_tblInputLoad').dataTable({
    "bJQueryUI": false,
    "sScrollY": "300px",
    "sScrollX": "100%",
    "sScrollXInner": "50%",
    "bScrollCollapse": true,
    "bPaginate": false,
    "bRetrieve": false,
    "bFilter": false,
    "bAutoWidth": false
  });
  new FixedColumns(oTable, {
    "iLeftColumns": 2,
    "iLeftWidth": 170,
    "bAutoWidth": false
  });
};

私の問題:HTMLページがレンダリングされると、テーブルの幅が原因で、右側のコンテナ全体が左側に浮きます。このデモでは、列数を19に設定しました。ただし、画面を最小化すると、すべてが意図したとおりに正しく表示されます。

私の質問:左に浮くのではなく、再フォーマットされたデータテーブルが正しく表示されるようにするにはどうすればよいですか?どんな助けでも大歓迎です。

4

2 に答える 2

0

コンテナにOverflow:hiddenを追加すると、以下に示すように問題が解決しました。

         <div id="div-input-load-cont" style="float: left; width: 100%; overflow: hidden; margin-top: 5px;
            height: 350px">
            <asp:PlaceHolder ID="phInputLoadData" runat="server" EnableViewState="False">
            </asp:PlaceHolder>
        </div>
于 2012-12-15T11:16:36.070 に答える
0

float:leftあなたはスタイルからクリアする必要があります

于 2012-12-15T08:56:29.030 に答える