MediaWiki:Datatables custom.js

From Comprehensible Input Wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$(document).ready( function () {
	
	if(document.getElementById('library')){
		// Create <thead> for DataTables to work
		var header = document.getElementById('library').createTHead().id = 'lib-thead';
		jQuery('#lib-header').detach().appendTo('#lib-thead');
		document.getElementById('tableHolder').style.display='block';
		
		// Activate DataTable
		console.log('waiting');
		var waitForDT = setInterval(function () {
			console.log('in it');
		    if (typeof $('#library').dataTable === 'function' && document.getElementById('tableHolder')) {
				
				document.getElementById('ciw-loading').style.display='none';
		
		        $('#library').dataTable( {
		        	searchPanes: {
			            viewTotal: true
			        },
					dom: 'Pliprtip',
					"order": [[ 0, 'desc' ]],
					scrollX: true,
					
					columnDefs: [
			            {
			                searchPanes: {
			                    show: false
			                },
			                targets: [0]
			            }
			        ]

		        } );
		
		
		        clearInterval(waitForDT);
		    }
		}, 100);
	}
});