データテーブルによる PHP スクリプトのソートおよび検索機能を実装しています。並べ替えは大丈夫です。検索には、3 つのテキスト フィールド、1 つの年齢層フィールド、1 つのドロップダウンがあります。dropdownbox の異なる値は、"owner"、"superadmin"、"admin"、および "agent" です。そのため、値「admin」を選択すると、「admin」と「superadmin」を含むレコードのリストが表示されます。「スーパー管理者」という単語に「管理者」という単語があるように、これが表示されていることは理解できます。したがって、このドロップダウンボックスのみについて、正確な単語を制限するにはどうすればよいですか。私のコードは次のようなものです:
<script type="text/javascript" >
(function($) {
$.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
// check that we have a column id
if ( typeof iColumn == "undefined" ) return new Array();
// by default we only wany unique data
if ( typeof bUnique == "undefined" ) bUnique = true;
// by default we do want to only look at filtered data
if ( typeof bFiltered == "undefined" ) bFiltered = true;
// by default we do not wany to include empty values
if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true;
// list of rows which we're going to loop through
var aiRows;
// use only filtered rows
if (bFiltered == true) aiRows = oSettings.aiDisplay;
// use all rows
else aiRows = oSettings.aiDisplayMaster; // all row numbers
// set up data array
var asResultData = new Array();
for (var i=0,c=aiRows.length; i<c; i++) {
iRow = aiRows[i];
var aData = this.fnGetData(iRow);
var sValue = aData[iColumn];
// ignore empty values?
if (bIgnoreEmpty == true && sValue.length == 0) continue;
// ignore unique values?
else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
// else push the value onto the result data array
else asResultData.push(sValue);
}
return asResultData;
}}(jQuery));
function fnCreateSelect( aData )
{
var r='<select><option value=""></option>', i, iLen=aData.length;
for ( i=0 ; i<iLen ; i++ )
{
r += '<option value="'+aData[i]+'">'+aData[i]+'</option>';
}
return r+'</select>';
}
function fnFilterColumn ( i )
{
$('#example').dataTable().fnFilter(
$("#col"+(i+1)+"_filter").val(),
i
);
}
/* Custom filtering function which will filter data in column four between two values */
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iMin = document.getElementById('min').value * 1;
var iMax = document.getElementById('max').value * 1;
var iVersion = aData[4] == "-" ? 0 : aData[4]*1;
if ( iMin == "" && iMax == "" )
{
return true;
}
else if ( iMin == "" && iVersion < iMax )
{
return true;
}
else if ( iMin <= iVersion && "" == iMax )
{
return true;
}
else if ( iMin <= iVersion && iVersion <= iMax )
{
return true;
}
return false;
}
);
$(document).ready(function(){
$('#example').dataTable( {
"bProcessing": true,
//"bServerSide": true,
"sAjaxSource": "datatabledb.php",
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"aButtons": [
{
"sExtends": "csv",
"sButtonText": "Save to CSV"
}
]
},
"oLanguage": {
"sSearch": "Search all columns:"
},
"aoColumns": [
null,
{ "bSortable": false }, // disable the sorting property for checkbox header
null,
null,
null,
null,
null,
null,
null,
null
]
} );
$("#example").dataTable().columnFilter(
{ aoColumns: [
null,
null,
null,
null,
null,
null,
null,
{
type: "select",
values: [ 'Owner', 'Superadmin', 'Admin','Agent' ]
},
null,
null
]
}
);
$("#col1_filter").keyup( function() { fnFilterColumn( 0 ); } );
$("#col3_filter").keyup( function() { fnFilterColumn( 2 ); } );
$("#col4_filter").keyup( function() { fnFilterColumn( 3 ); } );
//$("#col5_filter").keyup( function() { fnFilterColumn( 4 ); } );
//$("#col8_filter").keyup( function() { fnFilterColumn( 7 ); } );
var oTable = $('#example').dataTable();
/* Add event listeners to the two range filtering inputs */
$('#min').keyup( function() { oTable.fnDraw(); } );
$('#max').keyup( function() {oTable.fnDraw(); } );
//$('table').dataTable({"bFilter": false});
});
</script>
<table cellpadding="3" cellspacing="0" border="0" class="display userTable" aria-describedby="example_info">
<tbody>
<tr id="filter_col1">
<td>Name: </td>
<td><input type="text" name="col1_filter" id="col1_filter"></td>
<td>Email: </td>
<td><input type="text" name="col4_filter" id="col4_filter" /></td>
<td>Username: </td>
<td><input type="text" name="col3_filter" id="col3_filter" /></td>
<td>Min Age:</td>
<td><input type="text" id="min" name="min" maxlength="2" class="ageFeild" onkeypress="return numbersonly(event, false)" /></td>
<td>Max Age: </td>
<td><input type="text" id="max" name="max" maxlength="2" class="ageFeild" onkeypress="return numbersonly(event, false)" /></td>
<td style="padding-left:25px;">Privilege:</td>
</tr>
</tbody>
</table>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="form_table display" id="example">
<thead>
<tr>
<th class="sorting_asc">Name</th>
<th >Photo</th>
<th >Username</th>
<th >Email</th>
<th>Age</th>
<th>Location</th>
<th>Contact No</th>
<th>Privilege</th>
<th>Joining Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="10" class="dataTables_empty">Loading data from server</td>
</tr>
</tbody>
<tfoot>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>All Privilege</th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
そしてdatatabledb.phpページで、
...
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
if($aRow['admin_name'] != ''){
$row[] = wordwrap($aRow['admin_name'],15,"<br />\n",TRUE);
}
if($aRow['admin_photo'] == ''){
$row[] = "<img src='http://fgtpl.com/fugenx1/public_html/alertR/admins/upload/no-pic.jpg' width='50' height='50'>";
}
else if($aRow['admin_photo'] != ''){
if(!file_exists("http://fgtpl.com/fugenx1/public_html/alertR/admins/upload/".$aRow['admin_photo'])){$row[] = "<img src='http://fgtpl.com/fugenx1/public_html/alertR/admins/upload/no-pic.jpg' width='50' height='50'>";}
elseif(file_exists("http://fgtpl.com/fugenx1/public_html/alertR/admins/upload/".$aRow['admin_photo'])){$row[] = "<img src='http://fgtpl.com/fugenx1/public_html/alertR/admins/upload/".$aRow['admin_photo']."' width='50' height='50'>";}
}
if($aRow['username'] != ''){
$row[] = $aRow['username'];
}
if($aRow['email'] != ''){
$row[] = wordwrap($aRow['email'],15,"<br />\n",TRUE);
}
if($aRow['email'] == ''){
$row[] = "N/A";
}
if($aRow['age'] != ''){
$row[] = $aRow['age'];
}
if($aRow['age'] == ''){
$row[] = 0;
}
if($aRow['location'] != ''){
$row[] = $aRow['location'];
}
if($aRow['location'] == ''){
$row[] = "N/A";
}
if($aRow['contact_no'] != ''){
$row[] = $aRow['contact_no'];
}
if($aRow['contact_no'] == ''){
$row[] = "N/A";
}
if($aRow['role'] != ''){
$row[] = get_role_name_by_id($aRow['role']);
}
if($aRow['creation_date'] != ''){
$joiningDate = date("d-m-Y h:i:s", strtotime($aRow['creation_date']));
$row[] = substr($joiningDate,0,10);
}
if($aRow['status'] != ''){
$row[] = ($aRow['status'] == 1)?"Enable":"Disable";
}
$output['aaData'][] = $row;
}
...
私を助けてください。