标题不是垂直滚动数据表的表体

时间:2017-01-31 10:54:46

标签: javascript html css datatables yadcf

  

我添加了https://cdn.datatables.net/v/dt/jszip-2.5.0/pdfmake-0.1.18/dt-1.10.13/b-1.2.4/b-colvis-1.2.4/b-flash-1.2.4/b-html5-1.2.4/b-print-1.2.4/cr-1.3.2/sc-1.4.2/se-1.2.0/datatables.min.js   在我的html页面中,对于滚动功能,如果我添加更多列,它会重叠   窗口页面的其他内容或只是表体移动而不移动   头。正如其他帖子中提到的,我没有包含FixedHeader   html / js / css文件我无法在收到时添加测试页面   来自Web服务的数据,所以这是我的代码。   注意:我在标题

中添加了 Yadcf列过滤器
<html>
<head> 

<h2 style="color:#2196F3;">Ticket Data</h2>
</head>
<body>
<div class="container">
    <div class="row">

    </div>
    <div class="row">
        <div class="col-md-4 col-md-offset-3">
            <form action="" class="search-form">
                <div class="form-group has-feedback">
                    <label for="search" class="sr-only">Search</label>
                    <input type="text" class="form-control" name="search" id="search" placeholder="search" autocomplete="off"/>
                    <span class="glyphicon glyphicon-search form-control-feedback"></span>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
$(document).ready(function() {
     var realPath =$(&quot;#root&quot;)&#46;val();
        var webServicePathm = realPath+&quot;/mt/saasreporting/getopenticketsdata?&quot;;
        //var project = projectname.innerText;
        var parmUrl = &quot;project=test project&quot;;
        var webCallUrl = webServicePathm+parmUrl;

      var Table= $(&#39;#ex1&#39;).DataTable( {


          rowReorder: true,
            colReorder: true,
            /* fixedHeader: {
                header: true,

                },  */    
 &quot;ajax&quot;: {
   &quot;url&quot;:webCallUrl,
   &quot;dataSrc&quot;: function ( json ) {
       for ( var i=0, ien=json.length ; i&lt;ien ; i++ ) {
           json[i][0] = &#39;&lt;a href=&quot;/message/&#39;+json[i][0]+&#39;&gt;View message&lt;/a&gt;&#39;;
         }
         return json;
       }
 },
 &quot;columns&quot;: [
             { &quot;data&quot;: &quot;client&quot;, &quot;name&quot;: &quot;client&quot;, &quot;title&quot;: &quot;client&quot; },
             { &quot;data&quot;: &quot;project&quot;, &quot;name&quot;: &quot;project&quot;, &quot;title&quot;: &quot;project&quot; },
             { &quot;data&quot;: &quot;raisedOn&quot;, &quot;name&quot;: &quot;raisedOn&quot;, &quot;title&quot;: &quot;raisedOn&quot; },
             { &quot;data&quot;: &quot;ticketId&quot;, &quot;name&quot;: &quot;ticketId&quot;, &quot;title&quot;: &quot;ticketId&quot; },
             { &quot;data&quot;: &quot;assignedTo&quot;, &quot;name&quot;: &quot;assignedTo&quot;, &quot;title&quot;: &quot;assignedTo&quot; },
             { &quot;data&quot;: &quot;priority&quot;, &quot;name&quot;: &quot;priority&quot;, &quot;title&quot;: &quot;priority&quot; } 



         ],
         &quot;pagingType&quot;:&quot;full_numbers&quot;,
         select: true,

&quot;sDom&quot;: &#39;B&lt;&quot;clear&quot;&gt;Wfrtip&#39;,
lengthMenu: [
[ 10, 12, 50, -1 ],
[ &#39;10 rows&#39;, &#39;12 rows&#39;, &#39;50 rows&#39;, &#39;Show all&#39; ],
],

&quot;buttons&quot;: [
{
    className: &#39;b2&#39;,
extend:&#39;pageLength&#39;,
autoClose: true,
/* text: &#39;&lt;i class=&quot;fa fa-list-ol-3x&quot; aria-hidden=&quot;true&quot; style=&quot;color:#81ad30&quot;&gt;&lt;/i&gt;&#39;, */
titleAttr: &#39;no.of rows&#39;

},
{
    className: &#39;b2&#39;,
extend: &#39;colvis&#39;,
  autoClose: true,
 /*   text: &#39;&lt;i class=&quot;fa fa-columns-3x&quot; aria-hidden=&quot;true&quot; style=&quot;color:#81ad30&quot;&gt;&lt;/i&gt;&#39;, */
  titleAttr: &#39;Column Visibility&#39;,
  exportOptions: {
      columns: &#39;:visible&#39;,
  }
}
],

deferRender:    true,
scrollY:        true,
scrollCollapse: true,
"scrollX": true



        });

      new $.fn.dataTable.Buttons( Table, {
          buttons: [
              {
                  className: &#39;b1&#39;,
                                                extend:    &#39;copyHtml5&#39;,
                                                            /* text:      &#39;&lt;i class=&quot;fa fa-files-o&quot; style=&quot;color:green&quot;&gt;&lt;/i&gt;&#39;, */
                                   titleAttr: &#39;Copy&#39;,
                                            exportOptions: {
                                                    modifier: {
                                                        page: &#39;current&#39;
                                                    }
                                          }

                               },{
                                 className: &#39;b1&#39;,
                                            extend:    &#39;excelHtml5&#39;,
                                                           /*  text:      &#39;&lt;i class=&quot;fa fa-file-excel-o&quot; style=&quot;color:green&quot;&gt;&lt;/i&gt;&#39;, */
                                   titleAttr: &#39;Excel&#39;,
                                            exportOptions: {
                                                columns: &#39;:visible&#39;,
                                                modifier: {
                                                        page: &#39;current&#39;
                                                              }
                                            }
                               },{
                                 className: &#39;b1&#39;,
                                            extend:    &#39;csvHtml5&#39;,
                                                            /* text:      &#39;&lt;i class=&quot;fa fa-file-word-o&quot; style=&quot;color:green&quot;&gt;&lt;/i&gt;&#39;, */
                                titleAttr: &#39;CSV&#39;,
                                            exportOptions: {
                                            columns: &#39;:visible&#39;,
                                                modifier: {
                                                        page: &#39;current&#39;
                                                          }
                                            }

                               },
                {
                                 className: &#39;b1&#39;,
                                 extend:    &#39;pdfHtml5&#39;,
                                 message:&#39;Tickets Status&#39;,
                                           /*  text:      &#39;&lt;i class=&quot;fa fa-file-pdf-o&quot; style=&quot;color:red&quot;&gt;&lt;/i&gt;&#39;, */
                                   titleAttr: &#39;PDF&#39;,
                                   footer: true,
                                            exportOptions: {
                                                columns: &#39;:visible&#39;,

                                                 modifier: {
                                                                    page: &#39;current&#39;
                                   }
                          }
                               },
                 {
                        className: &#39;b1&#39;,
                        extend: &#39;print&#39;,
                        /* text: &#39;&lt;i class=&quot;fa fa-print&quot; aria-hidden=&quot;true&quot; style=&quot;color:blue&quot;&gt;&lt;/i&gt;&#39;, */
                        titleAttr: &#39;Print&#39;,
                        footer: true,
                        autoPrint: true,
                        exportOptions: {
                        columns: &#39;:visible&#39;,
                        modifier: {
                        page: &#39;current&#39;
                        }
                    }
                }
          ]
      } );

      Table.buttons( 1, null ).container().appendTo(
              Table.table().container()
);

      yadcf.init(Table, [
                            {
                column_number : 0,
                filter_type: "multi_select",
                select_type: 'select2',
                column_data_type: "text",
                html_data_type: "text",
                filter_default_label: "clients"                 
                            },
                            {
                column_number : 1,
                filter_type: "multi_select",
                select_type: 'select2',
                column_data_type: "text",
                html_data_type: "text",
                filter_default_label: "projects"
                            },
                            {
                column_number : 2,
                filter_type: "multi_select",
                select_type: 'select2',
                column_data_type: "text",
                html_data_type: "text",
                filter_default_label: "raisedOn"
                            },
                            {
                column_number : 3,
                filter_type: "multi_select",
                select_type: 'select2',
                column_data_Type: "text",
                html_data_type: "text",
                filter_default_label: "ticketId"
                            }, 
                            {
                column_number : 4,
                filter_type: "multi_select",
                select_type: 'select2',
                column_data_type: "text",
                html_data_type: "text",
                filter_default_label: "assignedTo"
                            } ,
                            {
                                column_number : 5,
                                filter_type: "multi_select",
                                select_type: 'select2',
                                column_data_type: "text",
                                html_data_type: "text",
                                filter_default_label: "tag"

                            } 

                   ]); 

      $('#search').on( 'click', function () {
          Table.search( this.value ).draw();
        } );

      function setTableBody() {
            $(".table.dataTable").height(
            $(".inner-container").height() - $(".table-header").height());
        }

        $(document).ready(function () {
            setTableBody();
            $(window).resize(setTableBody);
            $(".table-body").scroll(function () {
                $(".table-header").offset({
                    left: 160 - this.scrollLeft
                });
            });
        });
    });

    </script>


</body>
</html>

header is not scrolling vertically

0 个答案:

没有答案