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

No State Saving with $.fn.dataTableExt.afnFiltering.push

$
0
0
Hi all,

I have an XSL generated dropdown box to filter data by categories.
Everything is working fine, just the state saving for the custom column filter and the dropdown box is not working.

The data and the xsl template to build the table, the dropdown etc. ... is loaded by a php script with domDocument like this:

<?php
if (file_exists("blabla.xml")) {

/* load the xml file and stylesheet as domdocuments */
   $xsl = new DomDocument();
   $xsl->load("blabla.xsl");
  
   $inputdom = new DomDocument();
   $inputdom->preserveWhiteSpace=false;
   $inputdom->load("blabla.xml");
   $inputdom->save("blabla_2.xml");

/* create the processor and import the stylesheet */
   $proc = new XsltProcessor();
   $xsl = $proc->importStylesheet($xsl);

/* transform and output the xml document */
   $newdom = $proc->transformToDoc($inputdom);
   print $newdom->saveXML();

}
else {
   exit("Error. ");
}
?>


This is my code to build the dropdown box in the xsl template:

<select id="sCat">
<option value="-1">All Elements</option>
<xsl:for-each select="tblCaratCategory">
<option value="{@iCaratCategoryID}"><xsl:value-of select="@sCaratCategoryName" /></option>
</xsl:for-each>
</select>

And my js code:

$.fn.dataTableExt.afnFiltering.push(
	function ( oSettings, aData, iDataIndex ) {  
	var sID = $('select').val();
	var sData = aData[0]; 	  
	if (sID == sData)
		{
		return true;
		}
	  	else if (sID == "-1")
		{
			return true;
		}
		return false;
	}
);

$(document).ready(function() {
	
	var oTable = $('#example2').dataTable( {
	
		"iDisplayLength": 25,
		"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "Alle"]],
		"bStateSave": true,
		"fnStateSave": function (oSettings, oData) { localStorage.setItem( 'DataTables_'+window.location.pathname, JSON.stringify(oData) ); },
		"fnStateLoad": function (oSettings) { return JSON.parse( localStorage.getItem('DataTables_'+window.location.pathname) ); },
		"aoColumnDefs": [ { "bVisible": false, "aTargets": [ 0 ] } ], 	
		"sDom": '<"top"lfp<"clear">>rt<"bottom"lfp<"clear">>',
		"sPaginationType": "full_numbers",
		"oLanguage": {
			"sUrl": "xxxxx/datatables_lang_de.txt",
			"sSearch": "Search all columns:",
			},	
		"fnInitComplete": function(oSettings, json) { 
			alert( 'DataTables has finished its initialisation.' );
			}
	} );

	$('#sCat').change( function () {		
		oTable.fnDraw();	
	} );	
		
} );


Mhmmmm ....., hope somebody can help me out ;-)

Greetings

Michael

Viewing all articles
Browse latest Browse all 81688

Trending Articles



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