我在数据表中添加了默认的 Excel 按钮。
这是它的脚本:
$('#searchResult').DataTable(
{
"dom": '<"top"lB>rt<"bottom"ip>',
buttons: [
{
extend: 'excel',
exportOptions:
{
columns: ':visible'
}
},
'colvis']
)}
Run Code Online (Sandbox Code Playgroud)
我通过以下 css 将按钮放置在数据表上方的最右侧(顶部):
.dataTables_wrapper .dt-buttons {
float:right;
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在保持相同功能的同时用图标替换按钮(以改进 UI)。以及如何在与按钮完全相同的位置插入图标?
我想要做的是对数据表进行 ajax 搜索。由于某些原因,我没有考虑数据表提供的默认搜索功能,因此我创建了一个带有按钮的文本框。
在我的 Api 上,我为 javascript 函数发回了一个 Json
$("#buttonSearchDevice").on('click', function () {
var searchString = $("#searchString").val();
$.ajax({
url: "/Devices/LoadDevices",
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
data:
{
searchString: searchString
},
success: function (data) {
//if (data.length == 0)
// $('#devicesList').dataTable().fnClearTable();
//else {
// $('#devicesList').dataTable().fnClearTable();
// $('#devicesList').dataTable().fnAddData(data);
//}
}
});
});
Run Code Online (Sandbox Code Playgroud)
我尝试了注释代码来“刷新”我的数据表,但没有成功,我收到以下错误:
DataTables 警告:table id=devicesList - 为第 0 行、第 1 列请求未知参数“model”。有关此错误的更多信息,请参阅http://datatables.net/tn/4
我是否需要重新创建整个数据表(销毁和创建),还是可以使用新的新数据刷新它?
我想对 my 上某个列的值求和datatable,其中 x 列等于一个值,而 y 列等于另一个值。当我按如下方式对 X 列进行过滤时,我可以实现这一点:
dt.Compute("Sum([Cost])", "[COLUMNX] = 'blah'");
Run Code Online (Sandbox Code Playgroud)
这工作正常,但是我现在想向过滤器添加另一列,所以像 dt.Compute("Sum([Cost])", "[COLUMNX] = 'blah'", "[COLUMNY] = 'blah'");
请问如何过滤两个不同的列。
我一直试图让标签与 Jquery Datatables 一起工作大约 1 周,但没有运气!我已经浏览了 stackoverflow 并没有找到我正在寻找的帮助。
这篇文章很有见地:
我正在使用 jquery.tag-editor 创建标签并使用此代码我可以在全局搜索框中成功创建标签:
$('div.dataTables_filter input').tagEditor();
Run Code Online (Sandbox Code Playgroud)
我的问题是标签没有按预期过滤数据表,我知道需要重新绘制表格,但从我可以看到的情况来看,tagEditor 在搜索框内的 ul 内创建了 3 个 div:
<li><div class="tag-editor-spacer"></div>
<div class="tag-editor-tag">january</div>
<div class="tag-editor-delete"><i></i></div></li>
Run Code Online (Sandbox Code Playgroud)
中间的 div tag-editor-tag 包含我想用来过滤数据表的字符串。在更改时,它应该使用 tag-editor-tag div 中的值重绘表格。我认为这很接近,因为我已经看到了我想要它做什么,但不知道如何忽略 div 并获得中间值。
$('div.dataTables_filter input').change(function(){
table.fnFilter($('.....').text());
});
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。
我尝试在谷歌搜索如何更改数据表标题,我发现这个线程数据表 API:如何更改打印页面标题
这个线程的最佳答案是
var table = $('table').DataTable({
buttons: [
extend: 'print',
title: function(){
return foo.title
}
]
});
Run Code Online (Sandbox Code Playgroud)
我不明白它是如何工作的,这在控制台“indexOf..”中给了我错误
这是我要更改的图片 DataTable 网站定制打印示例
编辑 1尝试此代码
var table = $('table').DataTable({
buttons: [
extend: 'print',
title: function(){
var printTitle = 'New Title';
return printTitle.title
}
]
});
Run Code Online (Sandbox Code Playgroud) 我正在使用数据表来显示数据包含postingdate列,我需要更改postingdate列的格式,因为我找到了一些关于此的教程并在运行时使用了下面的代码。我收到错误消息,但没有出现表格。
错误信息:
数据表警告:表 id=users-table - Ajax 错误。有关此错误的更多信息,请参阅http://datatables.net/tn/7
代码:
$users = Checks::select(['details', 'postingdate', 'description', 'amount', 'type', 'slip', 'vendor_id', 'category_id']);
return Datatables::of($users)->editColumn('postingdate', function ($user) {
return $user->postingdate->format('d-m-Y')})->make(true);
Run Code Online (Sandbox Code Playgroud) 我在 DataGrid 中遇到问题。我需要在数据网格中使结果可点击。为此,我需要使用绑定结果显示一些结果和一些可点击的结果<DataGridTemplateColumn>
<DataGrid Name="Result" IsReadOnly="True" ItemsSource="{Binding Result}" AutoGenerateColumns="True" Height="200">
<DataGridTemplateColumn Header="Image">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<Button Content="{Binding Image}" Name="Image" Click="Button_Click" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)
但在结果中我得到了重复的列名,因为一个来自绑定结果,一个来自<datagridtemplatecolumn>. 有人可以帮我从绑定结果中删除重复的列名吗?
本题针对Datatables插件为JQuery.
我需要遍历所有表格行(甚至分页)并获取id每个tr元素。
像这样的 HTML 表格:
<table>
<thead>
<tr>
<th>Header content 1</th>
<th>Header content 2</th>
</tr>
</thead>
<tbody>
<tr id="etc_1_en">
<td>Etc 1</td>
<td>Etc 2</td>
</tr>
<tr id="etc_1_ru">
<td>Etc 3</td>
<td>Etc 4</td>
</tr>
<tr id="etc_1_fr">
<td>Etc 5</td>
<td>Etc 6</td>
</tr>
<tr id="etc_2_en">
<td>Foo 1</td>
<td>Foo 2</td>
</tr>
<tr id="etc_2_ru">
<td>Foo 3</td>
<td>Foo 4</td>
</tr>
<tr id="etc_2_fr">
<td>Foo 5</td>
<td>Foo 6</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
因此,如果最后 2 个字符不等于,我需要遍历每一行并隐藏行en(通过此检查一切正常,我正在使用substr)。
我可以遍历以下所有行:
tbl = $('#myTable').DataTable(); …Run Code Online (Sandbox Code Playgroud) 我正在实现 jQuery 服务器端数据表。我有 1 个日期列和 2 个日期时间列。所有 3 个都以错误的格式显示在数据表上。
收货日期:/Date(1373947200000)/ (Date)
创建日期:/Date(1374845903000)/ (Datetime)
更新日期:/Date(1374845903000)/ (Datetime)
如何以正确的格式显示?
.cshtml
<table id="disparityForm" class="ui celled table" style="width:100%">
<thead>
<tr>
<th>Status</th>
<th>Received Date</th>
<th>Member ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Created User</th>
<th>Created Date</th>
<th>Updated User</th>
<th>Updated Date</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Status</th>
<th>Received Date</th>
<th>Member ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Created User</th>
<th>Created Date</th>
<th>Updated User</th>
<th>Updated Date</th>
</tr>
</tfoot>
</table>
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.0/semantic.min.css" rel="stylesheet" />
<link href="~/Content/DataTables/media/css/dataTables.semanticui.min.css" rel="stylesheet" />
@section scripts{
<script src="~/Scripts/DataTables/media/js/jquery.dataTables.min.js"></script>
<script src="~/Scripts/DataTables/media/js/dataTables.semanticui.min.js"></script> …Run Code Online (Sandbox Code Playgroud)我从https://l-lin.github.io/angular-datatables/#/getting-started安装数据表角度指令
从https://l-lin.github.io/angular-datatables/#/extensions/buttons安装数据表按钮扩展
"styles": [
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/datatables.net-dt/css/jquery.dataTables.css",
"node_modules/datatables.net-buttons-dt/css/buttons.dataTables.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.js",
"node_modules/datatables.net/js/jquery.dataTables.js",
"node_modules/datatables.net-buttons/js/buttons.colVis.js",
"node_modules/datatables.net-buttons/js/buttons.flash.js",
"node_modules/datatables.net-buttons/js/buttons.html5.js",
"node_modules/datatables.net-buttons/js/buttons.print.js"
]
},
Run Code Online (Sandbox Code Playgroud)
"dependencies": {
"@angular/animations": "6.0.7",
"@angular/common": "6.0.7",
"@angular/compiler": "6.0.7",
"@angular/core": "6.0.7",
"@angular/forms": "6.0.7",
"@angular/http": "6.0.7",
"@angular/platform-browser": "6.0.7",
"@angular/platform-browser-dynamic": "6.0.7",
"@angular/platform-server": "6.0.7",
"@angular/router": "6.0.7",
"@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
"angular-datatables": "^6.0.0",
"aspnet-prerendering": "^3.0.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"datatables.net": "^1.10.19",
"datatables.net-buttons": "^1.5.3",
"datatables.net-buttons-dt": "^1.5.3",
"datatables.net-dt": "^1.10.19",
"jquery": "^3.3.1",
"jszip": "^3.1.5",
"rxjs": "^6.2.1",
"zone.js": "^0.8.26"
},
Run Code Online (Sandbox Code Playgroud)
当我运行这个项目然后返回这样的错误:在此处输入图像描述
未捕获的类型错误:无法读取 button.flash.js 中未定义的属性“版本”
datatable ×10
jquery ×6
datatables ×4
javascript ×4
c# ×2
css ×2
html ×2
.net ×1
ajax ×1
angular6 ×1
asp.net-mvc ×1
button ×1
laravel ×1
php ×1
wpf ×1
wpfdatagrid ×1