数据表搜索”;雄性“;和女性”;


DataTables Search "Male" and Female"

我使用的是数据表,它有一个内置的搜索(如果你这么称呼它的话),现在我在表列表中搜索性别时遇到了问题,因为每当我搜索"男性"时,男性和女性都会出现在列表中。如果我搜索"男性",它将只过滤性别"男性"。但是女性如果我搜索女性?如果我没有尝试任何东西,我很抱歉,因为我真的不知道。虽然我试过搜索,但那些和我有同样问题的人没有我能理解的答案,所以我只是试着也许你们能帮助我。如果你们不能,因为我什么都没试过,我理解。但我仍然抱有希望。提前感谢!

数据库名称-db_seq

表名-配置文件

表列-姓名、性别、用户名、密码

编辑:我的代码

<?php include('dbcontroller.php');
    $sql = "SELECT name, gender FROM profile ORDER by name ASC";
    $res = mysqli_query($conn,$sql)or die(mysqli_error());
    ?>
    <table id="batchList" class="table table-striped table-bordered" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Gender</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Gender</th>
            </tr>
        </tfoot>        
        <tbody> 
        <?php
        while ($row = mysqli_fetch_array($res)) {
            $name = $row['name'];
            $gender = $row['gender'];
        ?>
            <tr>
                <td><?php echo $name;?></td>
                <td><?php echo $gender;?></td>                  
            </tr>
<?php
    }
?>
    </tbody>
</table>
<?php
mysqli_close($conn);
?>

<script>
$(document).ready(function() {
    $('#batchList').DataTable();
} );
</script>

如果您使用ssp类,下面的示例可能会很有用。

ssp.class.php->过滤法

// Individual column filtering
    if ( isset( $request['columns'] ) ) {
        for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) {
            $requestColumn = $request['columns'][$i];
            $columnIdx = array_search( $requestColumn['data'], $dtColumns );
            $column = $columns[ $columnIdx ];
            $str = $requestColumn['search']['value'];
            if ( $requestColumn['searchable'] == 'true' &&
             $str != '' ) {
                if(!empty($column['db'])){
                    if ($requestColumn['search']['regex'] == 'true') {
                        $binding = self::bind( $bindings, $str, PDO::PARAM_STR );
                        $columnSearch[] = "`".$column['db']."` = ".$binding;
                    } else {
                        $binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
                        $columnSearch[] = "`".$column['db']."` LIKE ".$binding;
                    }
                }
            }
        }
    }

javascript DataTable的配置对象

initComplete: function () {
                this.api().columns().every( function () {
                    var that = this;
                    var column = this;
                    $( 'input', this.footer() ).on( 'keyup change clear', function () {
                        if ( that.search() !== this.value ) {
                            that
                                .search( this.value )
                                .draw();
                        }
                    } );
                    $( 'select', this.footer() ).on( 'change clear', function () {
                        if ( that.search() !== this.value ) {
                            if (this.value === '') {
                                that
                                    .search( this.value )
                                    .draw();
                            } else {
                                that
                                    .search( this.value, true, false)
                                    .draw();
                            }
                        }
                    } );
                } );
            },