$(document).ready(function() {
var oTable = $('#example').dataTable( {
"oLanguage": {
"sSearch": "Search all columns:"
},
"bStateSave": true
} );
)};
etc... etc...
<script type="text/javascript" charset="utf-8">
var asInitVals = new Array();
$(document).ready(function() {
/*
* Support functions to provide a little bit of 'user friendlyness' to the textboxes in
* the footer
*/
$("tfoot input").each( function (i) {
asInitVals[i] = this.value;
} );
$("tfoot input").focus( function () {
if ( this.className == "search_init" )
{
this.className = "";
this.value = "";
}
} );
$("tfoot input").blur( function (i) {
if ( this.value == "" )
{
this.className = "search_init";
this.value = asInitVals[$("tfoot input").index(this)];
}
} );
var oTable = $('#example').dataTable( {
"oLanguage": {
"sSearch": "Search all columns:"
},
"bStateSave": true,
"fnInitComplete": function() {
var oSettings = $('#example').dataTable().fnSettings();
for ( var i=0 ; i<oSettings.aoPreSearchCols.length ; i++ ){
if(oSettings.aoPreSearchCols[i].sSearch.length>0){
$("tfoot input")[i].value = oSettings.aoPreSearchCols[i].sSearch;
$("tfoot input")[i].className = "";
}
}
}
} );
$("tfoot input").keyup( function () {
/* Filter on the column (the index) of this element */
oTable.fnFilter( this.value, $("tfoot input").index(this) );
} );
} );
</script>
var oSettings = this.fnSettings();
jQuery("tfoot input").each( function (i) {
asInitVals[this.name] = this.value;
} );
jQuery("tfoot input").focus( function () {
if ( this.className == "search_init" )
{
this.className = "";
this.value = "";
}
} );
jQuery("tfoot input").blur( function (i) {
if ( this.value == "" )
{
this.className = "search_init";
this.value = asInitVals[this.name];
}
} );
...
jQuery("tfoot input").blur( function (i) {
if ( this.value == "" )
{
this.className = "search_init";
this.value = this.title;
}
} );
...
So, we don't need to use an array of initial values.
<tfoot>
<tr>
<th><input type="text" id="i-0" class="search_init"></th>
<th><input type="text" id="i-1" class="search_init"></th>
<th><input type="text" id="i-2" class="search_init"></th>
<th><input type="text" id="i-3" class="search_init"></th>
<th><input type="text" id="i-4" class="search_init"></th>
<th><input type="text" id="i-5" class="search_init"></th>
</tr>
</tfoot>
$("#example tfoot input").keyup( function () {
var id = $(this).attr('id').split("-")[1];
oTable.fnFilter( this.value, id );
});
$("tfoot input",__ctl00_content_datatableTable).keyup( function () {
/*Lets find the index after render (does not include the hidden columns). Then we must add N, N being the hidden columns with index<N */
var renderedIndex=$("tfoot input").index(this);
var hiddenColumnsCount=0;
var aoColumns=__ctl00_content_datatableTable.fnSettings().aoColumns;
for(i=0; i<=renderedIndex; i++) {
if (!aoColumns[i].bVisible)
{
hiddenColumnsCount++;
}
}
/* Filter on the column (the index) of this element */
__ctl00_content_datatableTable.fnFilter( this.value,renderedIndex+hiddenColumnsCount ,false,false,false);
});
/*
* Support functions to provide a little bit of 'user friendlyness' to the textboxes in
* the footer
*/
$("tfoot input").each( function (i) {
___ctl00_content_datatableasInitValsArray[i] = this.value;
} );
rubyan said: <span class="Author"><a href="/forums/profile/19188/rubyan">rubyan</a> </span>
<span class="DateCreated">
<a href="/forums/discussion/comment/26039#Comment_26039" class="Permalink" name="Item_12" rel="nofollow"></a></span>
oTable.fnFilter(this.value, oTable.oApi_fnVisibleToColumnsIndex(oTable.fnSettings(), $("thead input").index(this));
which works great for the initial filter. however, once i hide the columns, it remains correct. once i leave the page and come back to it, the cookies are read and the filter value is in the wrong index. i'm using the fnInitComplete function to put the values back into the inputs.
"fnInitComplete" : function(){
oTable = $j("#openTable").dataTable();
var oSettings = oTable.fnSettings();
for(var i = 0; i<oSettings.aoPreSearchCols.length; i++){
$("thead input")[i].value = oSettings.aoPreSearchCols[i].sSearch;
.......
(When i replace it with your idea, i lose the filter once i tab out of the column.)
$('#dataTable').dataTable({
"bStateSave": true,
} ).columnFilter({ sPlaceHolder: "head:after",
aoColumns: [{},
{type: "text"},
{type: "text"},
{}
]});
It looks like you're new here. If you want to get involved, click one of these buttons!
Get useful and friendly help straight from the source.