嗨,我有一个数据表问题(jquery)我无法解决我自己的问题。任何人都可以帮助我或给我一个提示吗?
问题是我的数据表的标题被移动了,格式不正确,如下图所示。
![在此处输入图片说明] [1]
但是当我点击一个条目以对其进行排序时,它会改变格式并且一切正常。
![在此输入图片说明] [2]
我已使用jquery ui tabs将数据表包含在jquery ui对话框中。我的代码看起来像这样。
<script>
$(function() {
$("#rt").treeview();
$("button").button({
icons: {primary: "ui-icon-person"}}).click(function() {
var id = this.id;window.location="rightsmanagement?nutzerrechte_vergeben&show=3&refine=";
});
});
$.fn.tabbedDialog = function () {
this.tabs();
var wWidth = $(window).width();
var dWidth = wWidth * 0.8;
var dialogOptions = {
modal: true,width: dWidth,minHeight: 520};
this.dialog(dialogOptions);
this.find('.ui-tab-dialog-close').append($('a.ui-dialog-titlebar-close'));
this.find('.ui-tab-dialog-close').css({'position':'absolute','right':'0', 'top':'13px'});
this.find('.ui-tab-dialog-close > a').css({'float':'none','padding':'0'});
var tabul = this.find('ul:first');
this.parent().addClass('ui-tabs').prepend(tabul).draggable('option','handle',tabul);
this.siblings('.ui-dialog-titlebar').remove();
tabul.addClass('ui-dialog-titlebar');
}
$(document).ready(function() {
$('#controllerTab').tabbedDialog();
});
$(document).ready(function() {
$('#singleusertable').dataTable({
"sScrollY": "280px",
"bPaginate": false,
"bAutoWidth": false,
"oLanguage": {"sUrl": "style/table/sprache.txt"},
"aoColumnDefs": [
{ "bVisible": false, "aTargets": [ 0 ] },
{ "sTitle": "Benutzername", "aTargets": [ 1 ] },
{ "sTitle": "Vorname", "aTargets": [ 2 ] },
{ "sTitle": "Nachname", "aTargets": [ 3 ] },
{ "sTitle": "Personalnummer", "aTargets": [ 4 ] },
{ "sTitle": "Abteilung", "aTargets": [ 5 ] },
{ "bVisible": false, "aTargets": [ 6 ] },
{ "sWidth": "25%", "aTargets": [ 1] },
],"aaSorting": [[0, 'desc']]
});
});
</script>
事先提示......
答案 0 :(得分:2)
单击选项卡单击时,必须添加触发器。在你的情况下,它将是这样的:
首先将数据表添加到变量中:
var oTable = $('#singleusertable').dataTable({
..
});
然后在单击第二个选项卡后重新加载。像这样:
$("a[href=#tabs-2]").click(function()
{
oTable.fnReloadAjax();
});
您的最终脚本将如下所示:
<script>
var oTable = null;
$(function() {
$("#rt").treeview();
$("button").button({
icons: {primary: "ui-icon-person"}}).click(function() {
var id = this.id;window.location="rightsmanagement?nutzerrechte_vergeben&show=3&refine=";
});
});
$.fn.tabbedDialog = function () {
this.tabs();
var wWidth = $(window).width();
var dWidth = wWidth * 0.8;
var dialogOptions = {
modal: true,width: dWidth,minHeight: 520};
this.dialog(dialogOptions);
this.find('.ui-tab-dialog-close').append($('a.ui-dialog-titlebar-close'));
this.find('.ui-tab-dialog-close').css({'position':'absolute','right':'0', 'top':'13px'});
this.find('.ui-tab-dialog-close > a').css({'float':'none','padding':'0'});
var tabul = this.find('ul:first');
this.parent().addClass('ui-tabs').prepend(tabul).draggable('option','handle',tabul);
this.siblings('.ui-dialog-titlebar').remove();
tabul.addClass('ui-dialog-titlebar');
}
$(document).ready(function() {
$('#controllerTab').tabbedDialog();
$("#controllerTab a[href=#tabs-2]").click(function()
{
oTable.fnDraw();
});
});
$(document).ready(function() {
oTable = $('#singleusertable').dataTable({
"sScrollY": "280px",
"bPaginate": false,
"bAutoWidth": false,
"oLanguage": {"sUrl": "style/table/sprache.txt"},
"aoColumnDefs": [
{ "bVisible": false, "aTargets": [ 0 ] },
{ "sTitle": "Benutzername", "aTargets": [ 1 ] },
{ "sTitle": "Vorname", "aTargets": [ 2 ] },
{ "sTitle": "Nachname", "aTargets": [ 3 ] },
{ "sTitle": "Personalnummer", "aTargets": [ 4 ] },
{ "sTitle": "Abteilung", "aTargets": [ 5 ] },
{ "bVisible": false, "aTargets": [ 6 ] },
{ "sWidth": "25%", "aTargets": [ 1] },
],"aaSorting": [[0, 'desc']]
});
});