最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Search not working with input tag on datatable 1.10 - Stack Overflow

programmeradmin1浏览0评论

I have example about search with datatable : jsfiddle/rmLLo7z2

If I remove input tag and put on it is text normal. It is search ok.

But it can't search with input tag.

I have example about search with datatable : jsfiddle/rmLLo7z2

If I remove input tag and put on it is text normal. It is search ok.

But it can't search with input tag.

Share Improve this question edited Mar 15, 2021 at 7:54 pavel 27.1k11 gold badges46 silver badges62 bronze badges asked Jan 6, 2015 at 7:09 Hoc NHoc N 1531 gold badge3 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

You need to set data-search and data-order attributes,

<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>

            </tr>
        </thead>

        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>

            </tr>
        </tfoot>

        <tbody>
            <tr>
                <td data-search="Tiger Nixon" data-order="Tiger Nixon"><input value="Tiger Nixon"/></td>
                <td data-search="System Architect" data-order="System Architect"><input value="System Architect"/> </td>
                <td data-search="Edinburgh" data-order="Edinburgh"><input value="Edinburgh"/></td>                
            </tr>
            <tr>
                <td data-search="Garrett Winters" data-order="Garrett Winters"><input value="Garrett Winters"/></td>
                <td data-search="Accountant" data-order="Accountant"><input value="Accountant"/> </td>
                <td data-search="Tokyo" data-order="Tokyo"><input value="Tokyo"/></td> 
            </tr>
            <tr>
                <td data-search="Ashton Cox" data-order="Ashton Cox"><input value="Ashton Cox"/></td>
                <td data-search="Junior Technical Author" data-order="Junior Technical Author"><input value="Junior Technical Author"/> </td>
                <td data-search="San Francisco" data-order="San Francisco"><input value="San Francisco"/></td> 
            </tr>
            <tr>
                <td data-search="Cedric Kelly" data-order="Cedric Kelly"><input value="Cedric Kelly"/></td>
                <td data-search="Senior Javascript Developer" data-order="Senior Javascript Developer"><input value="Senior Javascript Developer"/> </td>
                <td data-search="Edinburgh" data-order="Edinburgh"><input value="Edinburgh"/></td>                
            </tr>
    </tbody>
</table>

http://jsfiddle/rmLLo7z2/3/

More info about data-attributes: https://datatables/examples/advanced_init/html5-data-attributes.html

If data is loaded through Ajax or other sources,you can make use of render function like below.

            columns: [
                { 
                  data:'displayname',
                  width:'30%',
                  render: function(data,type,row)
                  {
                    if(type === 'filter'){
                      return data;
                    }
                    return '<input type="text" style="width:100%" value="'+data+'" name="Child_Displayname">';
                  },
                },
            ..]
发布评论

评论列表(0)

  1. 暂无评论