Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

jquery - 当列内容为html时,jQuery Datatables过滤列(jQuery Datatables filtering a column when the columns content is html)

I have a column in a dataTable that I want to filter.

(我在dataTable中有一列想要过滤。)

I can filter by columns which are defined like this:

(我可以按定义如下的列进行过滤:)

"columns": [
    { 
        "data": function (data) {
             return data['columnToFilter'];
        }
    },
];

But, I can't find a way to filter columns which are more than the original value, such as this one:

(但是,我找不到一种方法来过滤超出原始值的列,例如:)

"columns": [
    { 
        "data": function (data) {
            return '<h1>' + data['columnToFilter'] + '</h1>';
         }          
    }
];

How can I tell dataTables what raw the value (without the html) of the second column is?

(我怎样才能告诉dataTables第二列的原始值是什么(不含html)?)

Here is my code that does the filtering:

(这是我执行过滤的代码:)

$.fn.dataTable.ext.search.push(
    function( settings, data, dataIndex ) {
        // tabLocation can only be filtered if the value is returned without additional html
        var tabLocation = data[0];
        if ($("#myFilter").hasClass("down")) {
            return true;
        } else {
            if (tabLocation == 0) {
                return true;
            }
        }
    }
);

$.fn.toggleText = function(t1, t2){
    if (this.text() == t1) this.text(t2);
    else                   this.text(t1);
    return this;
};
  ask by user783322 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The solution I used was this:

(我使用的解决方案是这样的:)

"columns": [
    { 
        "data": function (data) {
            return data['columnToFilter'];
        },
        "render": {
            "display": function ( data, type, row, meta ) {
                return '<h1>' + data['columnToFilter'] + '</h1>';
            },
        },
        "bSortable": false,
    },
];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...