簡體   English   中英

jquery dataTable過濾/搜索不起作用

[英]jquery dataTable filter/search not working

我是jquery的新手,我使用了jqueryData表,我在搜索過程中遇到問題,
搜索正在前兩列(例如,如果我使用'QE5855'或3453457搜索其工作正常),但它不搜索第三列(例如,如果我輸入'United'或'united states'表是沒有排序),請幫助我。

<table id="agentDetails">
    <tr style="">
        <th width="22%">User Id</th>
        <th width="20%">Parent Id</th>
        <th width="35%">Country</th>
    </tr>
    <%
        for(UserDataModel getEachEmpDetails:phoneIdSiteMappingList){
    %>
        <tr>
            <td> <div><%=getEachEmpDetails.getUserUid %> </div> </td> // data is like 'QE5855'
            <td><div><%=getEachEmpDetails.getParentUid %> </div> </td> //data is like '3453457'
            <td><div><%=getEachEmpDetails.getCountry %> </div> </td>// data is like 'United States'
        </tr>   
    <%
        }
    <%

<script type="text/javascript">
    $( document ).ready(function() {
        var table = $("#agentDetails").DataTable({
             "bSort": false, 
            "iDisplayLength": 10 ,
            "sPaginationType": "full_numbers",
            "bSearchable":true,
            "bPaginate": true,
                "bFilter": true,
                 "sDom": '<"top"fip>',
                 "bStateSave": false,
                "oLanguage": {
                    "sInfo": "Showing _START_ to _END_ of _TOTAL_ messages",
                    "sInfoEmpty": "Showing 0 to 0 of 0 messages",
                    "sEmptyTable": " ",
                    "sSearch": "&nbsp&nbsp&nbsp",
                    "oPaginate": {
                        "sPrevious": "<",
                        "sNext": ">",
                        "sFirst":"",
                        "sLast":""
                    },
                    dom: 'T<"clear">lfrtip',
                    tableTools: {
                        "sRowSelect": "single"
                    }
                }
        }); 

    });
<script>

我不確定您使用的是哪個版本的Datatable ,但我希望這會有所幫助。 我應該說我沒有測試它,所以這個例子只是我認為問題所在的主要想法。

在你的JS代碼中,你可以指明你想要檢索表中數據的源,在這種情況下我使用C#,所以我使用“Url.Action”。 你應該在sAjaxSource中指出。 示例是這樣的......

 var oTable;
        $(function() {
            oTable = $('#agentDetails')
                .dataTable({
                "bServerSide": true,
                "bProcessing": true,
                "bSort": true,
                "sAjaxSource": "@Url.Action("Method")",
                "sPaginationType": "full_numbers",
                "bSearchable":true,
                "bFilter": true,
                "sDom": '<"top"fip>',
                "bInfo": true,
                "bLengthChange": false,
                "aoColumns": [
                    { "mData": "UserId" },
                    { "mData": "ParentId", "width": "22%", "bSortable": true},
                    { "mData": "Country", "width": "35%" },

                ],

        });

在aoColumns上,“mData”表示的方式不是映射您獲取方法的日期,因此您應該准確地知道模型中包含該值的var的名稱。 之后,您不需要使用for子句,數據表應該能夠自己處理搜索和過濾。

  <table id="agentDetails" >
                        <thead>
                            <tr>
                                <th>User Id</th>
                                <th>Parent Id</th>
                                <th>Country</th>

                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td></td>
                                <td></td>
                                <td></td>

                            </tr>
                        </tbody>
 </table>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM