0

My code can run and display database well, but Datatable plugin seem not work. I just try to enable sorting, ordering, searching. What wrong with my code?

    <html lang="en">
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.2/css/bootstrap-select.css">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.0/bootstrap-table.min.css">
      <link rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.2/js/bootstrap-select.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.0/bootstrap-table.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.0/locale/bootstrap-table-zh-CN.min.js"></script>
      <script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
      <script src="https://cdn.datatables.net/plug-ins/1.10.13/pagination/simple_numbers_no_ellipses.js"></script>
    <script>
    $('#example').dataTable( {
        "paging": true
    } );
    </script>
    <% 
    '---------------------------------------------------------------------------------
    strProvider="Provider=SQLOLEDB;server=sfn-sql01-cza.sfn.intra;uid=s44467_s44467;pwd=4N7D5Js;database=s44467_S44467;Connection Reset=FALSE"
    '---------------------------------------------------------------------------------
    set dbConn=Server.CreateObject("ADODB.Connection")
    dbConn.Open strProvider %>
    </head>
    <body>
    <% rowCount=0
    sqlTable = "select id, name from [sysobjects] where type in ('U','V','P') and category<>2 Order By Name "
    set rsSchema=dbConn.execute(sqlTable)
    %>
    <div class="container-fluid" style="height: 660px;">
    <form method="post">
    <table class="table table-bordered" style="letter-spacing: 2px; word-spacing: 3px;">
    <tr>
    <td colspan="4" class="success">
    <select  name="getTable" class="selectpicker form-control show-tick" data-live-search="true">
    <% do until rsSchema.EOF %>
       <option value='<%=rsSchema(0)%>'><%= rsSchema(1)%>
    <% rsSchema.MoveNext
    loop
    rsSchema.Close
    set rsSchema = Nothing %></option>
    </select></td></tr>
    <tr>
    <td class="info">
    <input style="width:100%" type="Submit" name="cmdSubmit" value="Show Data" class="btn btn-success btn-xs" data-placement="bottom" data-toggle="tooltip" title="Get  50 data">
    </td>
    <td class="info">
    <input style="width:100%" type="Submit" name="cmdSubmit" value="Show Column" class="btn btn-primary btn-xs" data-placement="bottom" data-toggle="tooltip" title="Get column">
    </td>
    <td class="info">
    <input style="width:100%" type="Submit" name="cmdSubmit" value="Database" class="btn btn-danger btn-xs" data-placement="bottom" data-toggle="tooltip" title="Get database name">
    </td>
    <td class="info">
    <input style="width:100%" type="Submit" name="cmdSubmit" value="Count" class="btn btn-warning btn-xs" data-placement="bottom" data-toggle="tooltip" title="Count info table">
    </td>
    </tr>
    <tr  class="danger">
    <td colspan=2><textarea  class="form-control" rows="1" name=txaQuery>select top 100 *  from </textarea></td>
    <td align=center  colspan=2><input style="width:100%" type=submit name="cmdSubmit" value="Execute" class="btn btn-primary btn" data-toggle="tooltip" title="Run query"></td></tr>
    </table>
    </form>
    <% if request.form("cmdSubmit") <>  "" then
        tableId = Request("getTable") 
        sqltableName = "select name from [sysobjects]  where id = " & tableId  
        set ors3 = dbconn.execute(sqltableName)
        strTable = ors3(0)
    %>
    <%  
    if request.form("cmdSubmit") = "Show Data" then
        strQuery = "select top 50 * from [" & strTable & "]"
        strLbl = "<p><b>" & strTable & "</b></p>"
    end if
    if request.form("cmdSubmit") = "Show Column" then
        strQuery = "select C.name as FieldName,T.name as DataType,C.length from syscolumns C,sysTypes T where C.id='" & request.form("getTable") & "' and C.xtype = T.xtype and C.xusertype = T.xusertype "
            strLbl = "<p><b>" & strTable & "</b></p>"
    end if 
    if request.form("cmdSubmit") = "Database" then
        strQuery = "SELECT name FROM master.dbo.sysdatabases"
        strLbl = "<p><b>" & strTable & "</b></p>"
    end if
    if request.form("cmdSubmit") = "Count" then
        strQuery = "SELECT count(*) FROM  [" & strTable & "]"
        strLbl = "<p><b>" & strTable & "</b></p>"
    end if
    if request.form("cmdSubmit") = "Execute" then
        strQuery = request.form("txaQuery")
         strLbl = "<p><b>" & strQuery & "</b></p>"
    end if
    strTable = "<i>" & strQuery & "</i>"
    set rsTable = dbConn.Execute(strQuery)   
    %>
      <b><%= strLbl %></b> 
       <table id="mytable" style="letter-spacing: 1px; word-spacing: 2px;" align="center" class="display table table-bordered table-responsive" data-toggle="table">
       <!-- begin column headers for selected table -->
       <thead>
       <tr><% for each field in rsTable.Fields %>
          <th><%= field.Name %></th>   
          <% next %></tr></thead>
       <% 'cycle thru the record set and display each row results
       do until rsTable.EOF %>
          <tbody><tr><% for each field in rsTable.Fields %>
             <td><%= field.Value %></td>
          <% next %></tr>
       <!--  next row = next record -->
       <% rowCount = rowCount+1
       rsTable.MoveNext
       loop
       dbConn.Close
       set dbConn = Nothing
       set rsTable = Nothing 
       %>
       </tbody>
       </table>
       <% if rowCount>10 then %>
          <div align=center></div>
       <% end if
       end if
    %>
    </div>
    </body>
    </html>
    </html>

The code is run well without error but the Datatable style was not applied. I dont know why?

1 Answer 1

1

Use

$(document).ready(function() {
    $('#example').DataTable( {
                "paging": true
            } );
} );

instead of

$('#example').dataTable( {
        "paging": true
    } );

then you have to put id of you table is 'example'.

and table tag must contains

<thead>
<tr>
<th>THead1</th>
<th>THead2</th>
...
<th>THeadN</th>
</tr>
</thead>
Sign up to request clarification or add additional context in comments.

4 Comments

Yes I already make this <thead><tr><% for each field in rsTable.Fields %><th><%= field.Name %></th><% next %></tr></thead> And the value will be loop, is that right? Thank you
thank you Ankikumar Tandel. I have edit the javascript and the id of table and it works well. Very thank you.
Can you help me more option for datable besides paging?
Tandel can you help me to make a form input for datasource in stead of using request.queryString from address bar?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.