jQuerydataTable插件如何使用?
How to use the jQuery dataTable plugin?
我的问题是因为我无法最小化 "Recursos Humanos" 和 "Nominas",如果我使用另一种类型的 table,例如,如果您最小化它,响应会很好。
enter image description here
这是:数据table响应enter image description here
好的,这是我使用 cdn
:
的代码
<table id="employeeTable" class="display nowrap" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>0,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>0,750</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>,000</td>
</tr>
<tr>
<td>Zorita Serrano</td>
<td>Software Engineer</td>
<td>San Francisco</td>
<td>56</td>
<td>2012/06/01</td>
<td>5,000</td>
</tr>
<tr>
<td>Jennifer Acosta</td>
<td>Junior Javascript Developer</td>
<td>Edinburgh</td>
<td>43</td>
<td>2013/02/01</td>
<td>,650</td>
</tr>
<tr>
<td>Cara Stevens</td>
<td>Sales Assistant</td>
<td>New York</td>
<td>46</td>
<td>2011/12/06</td>
<td>5,600</td>
</tr>
<tr>
<td>Hermione Butler</td>
<td>Regional Director</td>
<td>London</td>
<td>47</td>
<td>2011/03/21</td>
<td>6,250</td>
</tr>
<tr>
<td>Lael Greer</td>
<td>Systems Administrator</td>
<td>London</td>
<td>21</td>
<td>2009/02/27</td>
<td>3,500</td>
</tr>
<tr>
<td>Jonas Alexander</td>
<td>Developer</td>
<td>San Francisco</td>
<td>30</td>
<td>2010/07/14</td>
<td>,500</td>
</tr>
<tr>
<td>Shad Decker</td>
<td>Regional Director</td>
<td>Edinburgh</td>
<td>51</td>
<td>2008/11/13</td>
<td>3,000</td>
</tr>
<tr>
<td>Michael Bruce</td>
<td>Javascript Developer</td>
<td>Singapore</td>
<td>29</td>
<td>2011/06/27</td>
<td>3,000</td>
</tr>
<tr>
<td>Donna Snider</td>
<td>Customer Support</td>
<td>New York</td>
<td>27</td>
<td>2011/01/25</td>
<td>2,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/buttons/1.2.2/css/buttons.dataTables.css" rel="stylesheet" />
<link herf="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet" />
@section scripts{
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> @**@
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.4.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.4.2/js/buttons.html5.min.js"></script>
<script>
$(document).ready(function () {
$('#employeeTable').DataTable({
"scrollX": true,
dom: 'Bfrtip',
buttons: [ {
extend: 'excel',
title: 'ALIMENTOS DE CORTES:' + 'Planilla Produccion' ,
filename: 'PLANILLA PRODUCCION',
text: '<i class="fa fa-file-excel-o"></i> Excel'
}]
});
});
</script>
}
从 Datatables.net 下载所需的依赖项,例如 js 文件和 css 文件。
或
使用 CDN 链接。
CDN 链接是:
CSS:
<link rel="stylesheet" href="cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" />
JS:
<script type="text/javascript" src="cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
注意 : 使用文件顶部的.css
文件。在 @section scripts{}
中使用脚本 CDN——像这样:
@section scripts {
<script type="text/javascript" src="cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
//..
}
// 如果是下载的文件。
最佳做法是将所有依赖项包含在 App_Start/BundleConfig.cs
文件中。然后在 Global.asax
文件中注册所有包。
然后从 _Layout.cshtml
中的 Bundle.Config
文件访问所有脚本和 CSS,如下所示:
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery") // in the jquery bundle the the datatables files are included there.
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
有一件事非常重要...当所有依赖项将从 _Layout.cshtml
页面加载时,您想要访问 DataTable() 函数的视图...那必须使用那个 _layout页面否则无法正常工作。
最后访问 DataTable() 函数。
jQuery(document).ready(function(){
jQuery("#target_table_id").DataTable({
//...
//...
});
});
我的问题是因为我无法最小化 "Recursos Humanos" 和 "Nominas",如果我使用另一种类型的 table,例如,如果您最小化它,响应会很好。
enter image description here
这是:数据table响应enter image description here
好的,这是我使用 cdn
:
<table id="employeeTable" class="display nowrap" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>0,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>0,750</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>,000</td>
</tr>
<tr>
<td>Zorita Serrano</td>
<td>Software Engineer</td>
<td>San Francisco</td>
<td>56</td>
<td>2012/06/01</td>
<td>5,000</td>
</tr>
<tr>
<td>Jennifer Acosta</td>
<td>Junior Javascript Developer</td>
<td>Edinburgh</td>
<td>43</td>
<td>2013/02/01</td>
<td>,650</td>
</tr>
<tr>
<td>Cara Stevens</td>
<td>Sales Assistant</td>
<td>New York</td>
<td>46</td>
<td>2011/12/06</td>
<td>5,600</td>
</tr>
<tr>
<td>Hermione Butler</td>
<td>Regional Director</td>
<td>London</td>
<td>47</td>
<td>2011/03/21</td>
<td>6,250</td>
</tr>
<tr>
<td>Lael Greer</td>
<td>Systems Administrator</td>
<td>London</td>
<td>21</td>
<td>2009/02/27</td>
<td>3,500</td>
</tr>
<tr>
<td>Jonas Alexander</td>
<td>Developer</td>
<td>San Francisco</td>
<td>30</td>
<td>2010/07/14</td>
<td>,500</td>
</tr>
<tr>
<td>Shad Decker</td>
<td>Regional Director</td>
<td>Edinburgh</td>
<td>51</td>
<td>2008/11/13</td>
<td>3,000</td>
</tr>
<tr>
<td>Michael Bruce</td>
<td>Javascript Developer</td>
<td>Singapore</td>
<td>29</td>
<td>2011/06/27</td>
<td>3,000</td>
</tr>
<tr>
<td>Donna Snider</td>
<td>Customer Support</td>
<td>New York</td>
<td>27</td>
<td>2011/01/25</td>
<td>2,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/buttons/1.2.2/css/buttons.dataTables.css" rel="stylesheet" />
<link herf="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet" />
@section scripts{
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> @**@
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.4.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.4.2/js/buttons.html5.min.js"></script>
<script>
$(document).ready(function () {
$('#employeeTable').DataTable({
"scrollX": true,
dom: 'Bfrtip',
buttons: [ {
extend: 'excel',
title: 'ALIMENTOS DE CORTES:' + 'Planilla Produccion' ,
filename: 'PLANILLA PRODUCCION',
text: '<i class="fa fa-file-excel-o"></i> Excel'
}]
});
});
</script>
}
从 Datatables.net 下载所需的依赖项,例如 js 文件和 css 文件。
或
使用 CDN 链接。
CDN 链接是:
CSS:
<link rel="stylesheet" href="cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" />
JS:
<script type="text/javascript" src="cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
注意 : 使用文件顶部的.css
文件。在 @section scripts{}
中使用脚本 CDN——像这样:
@section scripts {
<script type="text/javascript" src="cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
//..
}
// 如果是下载的文件。
最佳做法是将所有依赖项包含在 App_Start/BundleConfig.cs
文件中。然后在 Global.asax
文件中注册所有包。
然后从 _Layout.cshtml
中的 Bundle.Config
文件访问所有脚本和 CSS,如下所示:
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery") // in the jquery bundle the the datatables files are included there.
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
有一件事非常重要...当所有依赖项将从 _Layout.cshtml
页面加载时,您想要访问 DataTable() 函数的视图...那必须使用那个 _layout页面否则无法正常工作。
最后访问 DataTable() 函数。
jQuery(document).ready(function(){
jQuery("#target_table_id").DataTable({
//...
//...
});
});