$("tfoot input").keyup( function () {
/* Filter on the column (the index) of this element */
oTable.fnFilter( this.value, $("tfoot input").index(this) );
} );
but
$("tfoot input").keyup( function () {
var oSettings = oTable.fnSettings();
var iCol = $("tfoot input").index(this)
oSettings.aoPreSearchCols[ iCol ].sSearch = this.value;
} );
oSettings.aoPreSearchCols[ iCol ].sSearch = this.value;
oSettings.aoPreSearchCols[ iCol ].sSearch = "^\\s*"+'1'+"\\s*$"; oSettings.aoPreSearchCols[ iCol ].bRegex = false; oSettings.aoPreSearchCols[ iCol ].bSmart= false;
jqFilter.keyup( function(e) {
/* Update all other filter input elements for the new display */
var n = oSettings.aanFeatures.f;
for ( var i=0, iLen=n.length ; i<iLen ; i++ )
{
if ( n[i] != this.parentNode )
{
$('input', n[i]).val( this.value );
}
}
/* Now do the filter */
if ( this.value != oSettings.oPreviousSearch.sSearch )
{
_fnFilterComplete( oSettings, {
"sSearch": this.value,
"bRegex": oSettings.oPreviousSearch.bRegex,
"bSmart": oSettings.oPreviousSearch.bSmart
} );
}
} );
{
"sExtends": "text",
"sButtonText": "Clear Search",
"fnClick": function ( nButton, oConfig, oFlash ) {
oUserTable.fnFeatureHtmlFilter (oUserTable._aoSettings);
oUserTable.fnDraw();
}
}
{
"sExtends": "text",
"sButtonText": "Clear Search",
"fnClick": function ( nButton, oConfig, oFlash ) {
oUserTable.fnFilter('');
oUserTable.fnDraw();
}
}
jQuery.fn.dataTableExt.oApi.fnSetFilteringPressEnter = function (oSettings) {
/*
* Type: Plugin for DataTables (www.datatables.net) JQuery plugin.
* Name: dataTableExt.oApi.fnSetFilteringPressEnter
* Version: 2.2.1
* Description: Enables filtration to be triggered by pressing the enter key instead of keyup or delay.
* Inputs: object:oSettings - dataTables settings object
*
* Returns: JQuery
* Usage: $('#example').dataTable().fnSetFilteringPressEnter();
* Requires: DataTables 1.6.0+
*
* Author: Jon Ranes (www.mvccms.com)
* Created: 4/17/2011
* Language: Javascript
* License: GPL v2 or BSD 3 point style
* Contact: jranes /AT\ mvccms.com
*/
var _that = this;
this.each(function (i) {
$.fn.dataTableExt.iApiIndex = i;
var $this = this;
var anControl = $('input', _that.fnSettings().aanFeatures.f);
anControl.unbind('keyup').bind('keypress', function (e) {
if (e.which == 13) {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter(anControl.val());
}
});
return this;
});
return this;
}
/* Example call */
$(document).ready(function() {
$('.dataTable').dataTable().fnSetFilteringPressEnter();
} );
using System;
using System.Linq;
using MvcCms.Data.DynamicLINQ;
using MvcCms.Service.Models;
using System.Linq.Expressions;
namespace MvcCms.Service.Code
{
public static class DataTablesSearch
{
//<summary>
//This implemenation of DataTables filter will be for small return sets.
//Will have another implementation for small sets that loads
//from the dom also. Both of these will have all fields searchable by default.
//Will have another using sprocs for all the searching for large tables.
//</summary>
public static IQueryable SearchForDataTables<T>(this IQueryable<T> query, DataTablesRequest dataTablesRequest, string[] columnNames)
{
if (!String.IsNullOrEmpty(dataTablesRequest.sSearch))
{
#region Search All Fields
var predicate = PredicateBuilder.False<T>();
if (dataTablesRequest.sSingleSearchField == "All")
{
Expression<Func<T, bool>> predicateToAdd = null;
for (int i = 0; i < dataTablesRequest.iColumns; i++)
{
if (dataTablesRequest.bSearchable[i]) // If the column is marked as searchable
{
string columnName = columnNames[i];
Type columnType = query.DynamicType(z => z[columnName]);
if (columnType == typeof(System.Int32))
{
var intToSearchFor = int.Parse(dataTablesRequest.sSearch);
//for integer we do equals
predicateToAdd = query.DynamicWhereForPredicateBuilder(z => z[columnName] == intToSearchFor);
}
else if (columnType == typeof(System.String))
{ //for string we do contains
predicateToAdd = query.DynamicWhereForPredicateBuilder(z => z[columnName].Contains(dataTablesRequest.sSearch)); //contains or
}
predicate = predicate.Or(predicateToAdd);
}
}
query = query.Where(predicate);
}
#endregion
#region Search Single Field
else if (!String.IsNullOrEmpty(dataTablesRequest.sSingleSearchField))
{
string columnName = dataTablesRequest.sSingleSearchField;
Type columnType = query.DynamicType(z => z[columnName]);
if (columnType == typeof(System.Int32))
{
try
{
var intToSearchFor = int.Parse(dataTablesRequest.sSearch);
//for integer we do equals
query = query.DynamicWhere(z => z[columnName] == intToSearchFor);
}
catch { }
}
else if (columnType == typeof(System.String))
{
//for string we do contains
query = query.DynamicWhere(z => z[columnName].Contains(dataTablesRequest.sSearch));
}
}
#endregion
}
return query;
}
}
}
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.