Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82129

Add class to custom TableTools button from fnRowSelected function within DT initialization

$
0
0
Hi,

The title of my post is pretty self-explanatory, so let me post some code here:

var oTable = $('#userTable').dataTable({
	"sDom": "<'row-fluid'<'span5'T><'span3'l><'span4'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
	"bServerSide": "true",
	"sAjaxSource": "arch/users/Utils.cfc?method=getRecordsForGrid",
	"sPaginationType": "bootstrap",
	"oLanguage": {
		"sLengthMenu": "_MENU_ records per page",
		"sInfoFiltered": "(_MAX_ total)"
	},
	"aoColumnDefs": [
		<cfset ii = 0>
		<cfoutput>
			<cfset ii = 0>
			{ "aDataSort": [ 2, 0, 1 ], "aTargets": [ 2 ] },
			{ "mData": "name", "aTargets": [ #ii# ] }, <cfset ii = ii + 1>
			{ "mData": "user_name", "aTargets": [ #ii# ] }, <cfset ii = ii + 1>
			{ "mData": "group.name", "aTargets": [ #ii# ] }, <cfset ii = ii + 1>
			{ "mData": "user_type.name", "aTargets": [ #ii# ] }, <cfset ii = ii + 1>
			{ "mData": "email", "aTargets": [ #ii# ] }, <cfset ii = ii + 1>
			{ "mData": "user_type", "aTargets": [ #ii# ], "bVisible": false }, <cfset ii = ii + 1>
			{ "mData": "status_cde.name", "aTargets": [ #ii# ], "bVisible": false }, <cfset ii = ii + 1>
			{ "mData": "addr1", "aTargets": [ #ii# ], "bVisible": false }, <cfset ii = ii + 1>
			{ "mData": "addr2", "aTargets": [ #ii# ], "bVisible": false }, <cfset ii = ii + 1>
			{ "mData": "city", "aTargets": [ #ii# ], "bVisible": false }, <cfset ii = ii + 1>
			{ "mData": "state", "aTargets": [ #ii# ], "bVisible": false }, <cfset ii = ii + 1>
			{ "mData": "zip", "aTargets": [ #ii# ], "bVisible": false }, <cfset ii = ii + 1>
			{ "mData": "country", "aTargets": [ #ii# ], "bVisible": false }, <cfset ii = ii + 1>
			{ "mData": "phone", "aTargets": [ #ii# ], "bVisible": false }, <cfset ii = ii + 1>
			{ "mData": "fax", "aTargets": [ #ii# ], "bVisible": false }, <cfset ii = ii + 1>
			{ "mData": "hint", "aTargets": [ #ii# ], "bVisible": false } <cfset ii = ii + 1>
		</cfoutput>
	],
	"oTableTools": {
		"sRowSelect": "single",
		"sSelectedClass": "row_selected",
		"fnRowSelected": function ( node ) {
			user_type = oTable.fnGetData(node[0]).user_type.value;
			user_id = oTable.fnGetData(node[0]).DT_RowId;
			if ((user_type.trim() === 'A') || (user_type.trim() === 'B')) {
				$('#ToolTables_userTable_3').addClass('disabled');
			}
		},
		"aButtons": [
			{ "sExtends": "editor_create", "editor": editor },
			{ "sExtends": "editor_edit",   "editor": editor },
			{ "sExtends": "editor_remove", "editor": editor }
		]
	}
});
$('#userTable_filter input').addClass('search-query');

var oTableTools = new TableTools(oTable, {
	"aButtons": [
	{
		"sExtends": "select_single",
		"sButtonText": "<i class='icon-external-link icon-large icon-align'></i>&nbsp;&nbsp;Manage Access",
		"fnClick": function ( node ) {
			if ($(node).hasClass('disabled')) {
				return false;
			} else {
				showSubAccessPanel(user_id);
			}
		}
	}]
});
$('#userTableDiv .span5').first().append(oTableTools.dom.container);

Basically, I think I'm just having a scope issue. The

if ((user_type.trim() === 'A') || (user_type.trim() === 'B')) {}

check runs correctly, but the button I'm trying to affect isn't getting updated. Is there a different way I could go about trying to affect this button from within fnRowSelected? The ID I'm using to target it is just the dynamically generated ID and I would think it should be available.

I've tried adding an fnRowSelected function doing the same thing in the custom TableTools button initialization but that doesn't work. I think it's because fnGetData isn't working; not sure.

Thanks,
Carl

Viewing all articles
Browse latest Browse all 82129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>