1

I've been battling with this problem for a while now. The width of my jQuery DataTable is only displayed correctly after I resize the screen. Watch this screencast to see what happens:

http://screencast.com/t/QY2ZgZp4By

Here's the scenario:

Using ASP.NET I import data from CSV file and dynamically build a table. The file has a variable number of columns - so it can be any number of columns.

After I produce the table I call the DataTable script to format the table as show below:

        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

The table is inserted into a ASP.NET placeholder as show below:

  <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>

And here is the script to format the table:

    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
  });
};

My problem: when the HTML page is rendered my entire right-hand-side container floats to the left due to the width of the table. In this demo I set the number of columns to 19. However, when I minimize the screen everything is displayed correctly the way it is meant to be.

My question: what do I do to make sure the reformatted datatable is shown correctly, instead of floating left? Any help would be greatly appreciated.

user1309226
  • 739
  • 1
  • 10
  • 31
  • Does this question bear any relevance? http://stackoverflow.com/questions/8278981/datatables-on-the-fly-resizing – ddoxey Dec 15 '12 at 08:03

2 Answers2

0

you should clear float:left from style

Chakavak Behzad
  • 807
  • 1
  • 9
  • 13
  • Could you add a bit more detail on how/where exactly that should be done? – Brooks Moses Dec 15 '12 at 09:15
  • you want place in center your table?? – Chakavak Behzad Dec 15 '12 at 09:26
  • The formatted data table should be positioned next to the navigation pane and not under it. If you watch the screencast you will notice it everthing works fine after I resize the screen. Perhaps the problem here is that the table is being created dynamically after a postback. – user1309226 Dec 15 '12 at 10:51
0

Adding Overflow:hidden to the container solved the problem as show below:

         <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>
user1309226
  • 739
  • 1
  • 10
  • 31