搜索不适用于数据表 1.10 上的输入标记



我有关于使用数据表搜索的示例:jsfiddle.net/rmLLo7z2

如果我删除输入标签并戴上它是文本正常的。这是搜索确定的。

但它无法使用输入标签进行搜索。

您需要设置data-searchdata-order属性,

<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.net/rmLLo7z2/3/

更多信息 data-attributes : https://datatables.net/examples/advanced_init/html5-data-attributes.html

如果数据是通过 Ajax 或其他源加载的,则可以使用如下所示的渲染函数。

            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">';
                  },
                },
            ..]

最新更新