我在Datatables中尝试了一些方法,在该方法中,我使用jquery隐藏了页面加载时的列,但是当您切换复选框并重新加载页面时(当复选框仍处于选中状态时),它仍然隐藏了该列。有没有更简单的方法可以做到这一点?基本上,当页面再次加载时,如果相关复选框仍处于选中状态,则选中该列时将其显示。在CSS中,该列设置为“ display:none”。
/*ID of checkbox- when it's checked, show the column, else do not*/
$adminUserAccountsShowHideProfiles.change(function(e) {
var $profileColumn = $adminUserAccountsTable.find('.admin-user-accounts-profile-column');
if ( $(this).is(':checked') ) {
$profileColumn.show();
} else {
$profileColumn.hide();
}
});
/*Table Code*/
if (!userAccountsDTO) {
userAccountsDTO = $adminUserAccountsTable.DataTable({
destroy:true,
data:normalizedData,
columns:userAccountsMap,
autoWidth:false,
paging:false,
dom:'lftip',
2 = user name, 0 = invisible child indicator sort
orderFixed: {
post: [[2,'desc'],[0, 'desc']]
},
order:[4,'asc'],
language:{
search:'',
searchPlaceholder:ax.L(5008),
emptyTable: ax.L(905),
zeroRecords: ax.L(905),
info: tableFilters.info,
infoFiltered: tableFilters.infoFiltered,
infoEmpty: tableFilters.info
},
rowCallback:function(row, data, index) {
var $row = $(row);
var uname = data.username.replace(/[@._#]/gi,'-');
var id = data.id;
$row.data('username',uname);
$row.data('id',id);
if (!data.enabled) {
$row.addClass('row-disabled');
}
if (data.current_profile.id != data.default_profile.id) {
$row.addClass('childrow un-'+id);
} else {
$row.addClass('parentrow un-'+id);
}
}
});
ax.Utils.setupTableFiltering($adminUserAccountsTable, userAccountsDTO, MAX_RESULTS, { visibleOnly: true });
var $profileColumnHidden = $adminUserAccountsTable.find('.admin-user-accounts-profile-column').hide();
} else {
userAccountsDTO.clear();
userAccountsDTO.search('');
userAccountsDTO.rows.add(normalizedData);
userAccountsDTO.draw();
}