简体   繁体   English

jquery dataTable过滤/搜索不起作用

[英]jquery dataTable filter/search not working

I am new to jquery and I have used the jqueryData Table, I am facing problem in during search, 我是jquery的新手,我使用了jqueryData表,我在搜索过程中遇到问题,
Search is working for first two columns (ex., if I search using 'QE5855' or 3453457 its working fine), But its not searching for the third column (ex., if I enter 'United' or 'united states' table is not getting sorted) , Please help me. 搜索正在前两列(例如,如果我使用'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>

I'm not sure which version of Datatable are you using but I hope this helps. 我不确定您使用的是哪个版本的Datatable ,但我希望这会有所帮助。 I should to say that I didn't test it, so the example is just the main idea where I think the problem is. 我应该说我没有测试它,所以这个例子只是我认为问题所在的主要想法。

On your JS code you can indicate the source from you want to retrieve the data on the table, in this case I'm using C# so I use "Url.Action". 在你的JS代码中,你可以指明你想要检索表中数据的源,在这种情况下我使用C#,所以我使用“Url.Action”。 You should to indicate that in sAjaxSource. 你应该在sAjaxSource中指出。 Example is something like this... 示例是这样的......

 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%" },

                ],

        });

On aoColumns "mData" means the way than you al mapping the date that are you getting of your method so you should exactly the name of the var that contains that value in your model. 在aoColumns上,“mData”表示的方式不是映射您获取方法的日期,因此您应该准确地知道模型中包含该值的var的名称。 After that you don't need to use a for clause and the datatable should to be able to handled the searching and filter for it self. 之后,您不需要使用for子句,数据表应该能够自己处理搜索和过滤。

Example

  <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