Javascript datatables取代了2+;带有一个空格的空格+;我能阻止这一切吗? 老虎尼克松 系统架构师 爱丁堡 61 2011/04/25 $320,800

Javascript datatables取代了2+;带有一个空格的空格+;我能阻止这一切吗? 老虎尼克松 系统架构师 爱丁堡 61 2011/04/25 $320,800,javascript,jquery,datatables,Javascript,Jquery,Datatables,我注意到datatables删除了2+个空格,并将其替换为馈入datatables的数据中的1个空格。这可以在上面的老虎尼克松中看到。因此,在数据表中,它显示为老虎尼克松(带一个空格)。因此,我可以通过搜索老虎尼克松(带一个空格)找到老虎尼克松。作为一个愚蠢的例子,如果我想找到老虎尼克松(带一个空格)中所有空格的老虎尼克松,该怎么办 International Telecommunications Investment and Commerce Joint Stock Company

我注意到datatables删除了2+个空格,并将其替换为馈入datatables的数据中的1个空格。这可以在上面的老虎尼克松中看到。因此,在数据表中,它显示为
老虎尼克松
(带一个空格)。因此,我可以通过搜索
老虎尼克松
(带一个空格)找到
老虎尼克松
。作为一个愚蠢的例子,如果我想找到
老虎尼克松
(带一个空格)中所有空格的
老虎尼克松
,该怎么办

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
下面是我的例子来说明这一点

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
这更像是我刚刚发现的一个观察结果,但我想知道是否有一种方法可以阻止datatables这样做。这样数据就可以准确地传递到数据表

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
注意作为旁白,我有另一个datatables示例,它使用了2+空格,datatables保留了2+空格,但我无法在这里说明这一点

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces

请注意:

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
如果我在数据库中搜索2个空格

select * from xyz23 where Device_Manufacturer LIKE '%International  %';
                                                                  ^^2spaces
International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
它将使用2个空格返回4个结果

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
在数据表中搜索此项:

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
International  
             ^^2spaces
将返回4个结果,但它们在数据表中只有1个空间:

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
International Telecommunications Investment and Commerce Joint Stock Company
             ^1space
即使数据库返回2个空格(见chrome中网络XHR响应下的响应)

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
但基于下面的@davidkonrad答案“……简单地说,HTML是如何呈现的……”,这是有道理的,尽管这让我在理解这一点之前有点困惑

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
但是,如果我在datatables中搜索:

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
International T
             ^1space
我不会得到任何结果,这与它使用下面的2个空格找到它时显示的结果不同

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
但如果我在数据表中搜索:

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
International  T
             ^^2spaces
我用1个空格得到4个结果:

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
International Telecommunications Investment and Commerce Joint Stock Company
             ^1space
所以这可能有点让人困惑,但我现在更好地理解了这一点,感谢@davidkonrad在下面介绍的方法

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces

EDIT1-供我参考 只需在第1列执行此操作:使用
targets:0,

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
var table = $('#example').DataTable({
  columnDefs : [{
    targets: 0,
    render: function(data, type, row, meta) {
       return '<pre>' + data + '</pre>'
    }
  }]

});
var table=$('#示例').DataTable({
columnDefs:[{
目标:0,
呈现:函数(数据、类型、行、元){
返回“”+数据+“”
}
}]
});

这完全是意料之中的事。“替换”空白的不是数据表,而是阅读器/浏览器呈现HTML的方式。空白应该保留或减少到绝对最小值

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
如果要保留空白,可以将内容包装成

更新的小提琴->尝试搜索“老虎”

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces

更新。考虑空格的自定义筛选器的示例

International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces
$.fn.dataTable.ext.search.push(函数(设置、数据、数据索引){
var term=$('.dataTables_filter input').val().replace(/\s/,'');
如果(!term)返回true;

对于(var i=0,l=data.length;i

tks)来说,这是一个非常好的答案。我在我的笔记中添加了一个“进一步”在你帮助我回答的问题中。如果你愿意,尽管不是完全必要,但请评论/确认我的回答是正确的。@HattrickNZ,我明白你的意思。你是对的。你需要一个自定义过滤器来完成你需要的工作。请参阅更新的fiddle/答案。我对正则表达式不太熟练,所以我刚刚做了一个愚蠢的
'
重播粘贴到
。尝试在更新的小提琴中搜索
'
International  Telecommunications Investment and Commerce Joint Stock Company 
             ^^2spaces