1

I was working on MVC3 with Jquery DataTables. There every grid consist of search function where it searches the content by matching input character (say like, using contains). But I need the result should be using StartsWith.

I need something like this,

Grid Records

1. Pipefitting Annotated instructor guide level 1 CD-ROM
2. Adobe Photoshop CS4 for photographers A professional image editors

If I Input character 'a', the result should come with second row (By searching starting character of the word in a string). or If I type 'g' then the result should be of first record.

I have googled a lot but I haven't find anything that matches my requirement. Please suggest me how can i do this.

View Code

    $(document).ready(function () {
    $('#CollectionTable').dataTable({
      "bJQueryUI": true,
      "sPaginationType": "full_numbers"}).makeEditable({
            "aoColumns": [
                null, null
                ]
        });
    });
4

2 回答 2

1

使用数据表 1.10.9,搜索以您将输入的参数开头的值非常简单。

我自己做了一些研究,但是 datatables API 有内置的列过滤器来做你正在寻找的东西。

var table = $('#table_id').DataTable();

        $('#name').on( 'keyup', function () {

            table
                .columns( 0 ) // 0 based column
                .search( "^"+this.value, true, true, true )
                .draw();

        } );

table 是数据表对象

#name 是我从中传递参数的输入框。

您可以定义您感兴趣的列,然后在针对您的参数进行搜索时传入正则表达式查询。

您可以在此处的官方文档中找到上述示例

于 2015-10-30T01:25:59.490 回答
0

fnFilter 允许您使用正则表达式过滤表:

$(document).ready(function() {
  var oTable = $('#example').dataTable();

  // Sometime later - filter...
  oTable.fnFilter( '^' + yourTerm, null, true, true, true, true);
} );

完整参考:http ://www.datatables.net/ref

于 2013-01-24T13:51:56.257 回答