jQuery数据类型从所选选项列排序和排序 [英] jQuery datatable sort and order from selected option column

查看:88
本文介绍了jQuery数据类型从所选选项列排序和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jquery datatable,我需要在选定的选项< select>< option selected =selected>中的文本中包含html选择输入的单元格内进行过滤和排序。 **要过滤的文本**< / option>< / select>



所以我需要搜索表中的行它包含一个包含选择框的td,其中我选择了用于搜索的文本的选项。



所以如果在单元格中选择了要过滤的文本该行必须可见。
有可能吗?如何做?



谢谢

解决方案

我想使用自定义过滤,我想。
http://datatables.net/release-datatables/examples /plug-ins/range_filtering.html



看到这个jsfiddle: http://jsfiddle.net/DYyLd/



搜索x,只显示选择x的行。更改所选择的选项,搜索将根据需要找到它/忽略它。

  $。fn.dataTableExt.afnFiltering.push(
function(oSettings,aData,iDataIndex){
var oTable = $('#myTable')。dataTable();
var nodes = $(oTable.fnGetNodes(iDataIndex));
var selItem = nodes.find('select' ();

//这是基本的,您应该拆分字符串,并为每个子字符串查找
//
var filterValue = $('div.dataTables_filter input') .val();

return(selItem.indexOf(filterValue)!== -1);
}
);

另外,我补充说:

  $('select')。click(function(){$('#myTable')。dataTable()。fnDraw();}); 

当任何选择被更改时,它会重新绘制表 - 这样,它们被重新过滤。



如示例中所述,我的搜索功能非常基本,只查看选择框中所选项是否包含搜索字段中的确切文本敏感。你几乎肯定要用空格拆分字符串,并搜索selItem中的每个子字符串。还要注意,这个方法不会搜索其他的列 - 它只在列中使用选择框。您可能还想搜索其他列。



bqb


I have a jquery datatable and I need to filter and sort inside a cell that contains html select inputs by the text in the selected option <select><option selected="selected">**text to filter**</option></select>.

So I need to search the rows in the table that contain a td that contains a select box where I've selected the option with the text used for the search.

So if in a cell I choose the option with "text to filter" text that row must be visible. Is it possible? How can I do it?

Thank you

解决方案

You'll want to use custom filtering, I think. http://datatables.net/release-datatables/examples/plug-ins/range_filtering.html

See this jsfiddle: http://jsfiddle.net/DYyLd/

Search for "x" and only the row with "x" selected will show. Change the selected option, and the search will find it/omit it as appropriate.

$.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {
        var oTable = $('#myTable').dataTable();
        var nodes = $(oTable.fnGetNodes(iDataIndex));
        var selItem = nodes.find('select').val();

        // This is basic.  You should split the string and look
        // for each individual substring
        var filterValue = $('div.dataTables_filter input').val();

        return (selItem.indexOf(filterValue) !== -1);
    }
);

Also, I added this:

$('select').click(function() { $('#myTable').dataTable().fnDraw(); });

which redraws the table when any of the selects are changed - that way, they are re-filtered.

As commented in the example, my search function is very basic, only looking to see if the selected item in the select box contains the exact text in the search field, case sensitive. You would almost certainly want to split the string by spaces, and search for each substring in selItem. Also notice this method doesn't search other the column(s) - it only looks in the column with the select box. You may want to search the other columns as well.

bqb

这篇关于jQuery数据类型从所选选项列排序和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆