【问题标题】:Yadcf custom_func doesn't recognize column value with a radio button.Yadcf custom_func 无法识别带有单选按钮的列值。
【发布时间】:2016-03-04 00:01:54
【问题描述】:

我正在尝试将 Yadcf 与 DataTables 1.10+ 一起使用。我的情况是我的数据表中的每一行都有一个带有 4 个单选按钮的列。我希望能够使用 Yadcf 过滤该数据。如果不使用自定义函数,我找不到任何方法来做到这一点。

yadcf.init(oTable, [
       // { column_number: 0 },
       // { column_number: 1 },
        {
            column_number: 2,
            filter_type: "text"
        },
        {
            column_number: 3,
            filter_type: "text"
        },
       // { column_number: 4 },
        {
            column_number: 5,
            filter_type: 'custom_func',
            custom_func: statusFilter,
            data: JSON.parse(jsonStatus)

您可以在第 5 列看到我调用了一个名为 statusfilter 的自定义函数

function statusFilter(filterVal, columnVal) {
    var found;

    if (columnVal === '') {
        alert('here');
        return true;
    }
}

它正确传递了 filterVal 但 columnVal 为空,因此引发我的警报并返回。

我尝试浏览一下代码,发现 yadcf 看到第 5 列的 aData 为空。我不确定为什么。

有没有人知道我如何才能完成这项工作。

谢谢,

【问题讨论】:

  • 您可能需要在选择该行上的收音机时更新数据表模型,但如果没有示例 jsbin / jsfiddle 我无能为力,您可以修改以下 jsbin jsbin.com/mexemavusu/edit?js,output
  • 我更新了那个 jsbin。 jsbin.com/dudulapobe/edit?js,output 它确实传递了一个列值。不幸的是,它将所有单选按钮作为列值传递。我猜我是空白的原因是因为它是通过 Ajax 加载的,但这似乎也是一个问题。

标签: jquery datatables-1.10 yadcf


【解决方案1】:

我已对0.9.0.beta.11custom_func - 第 4 个参数添加了增强功能 - 它保存了表格行的 html DOM。查看jsbin sample 并检查我是如何使用它的。

function myCustomFilterFunction(filterVal, columnVal, rowVal, stateVal) {
    if (columnVal === '') {
        return true;
    }

    if ($(stateVal[0]).filter(':checked').val() === filterVal) {
        return true;
    }
    return false;
}

问题是你必须找到一种方法来更新你的 DOM 鼠标 readio 按钮选择,以便过滤器会看到新值被 检查 - 让我知道你最终是如何做到的 - 也许使用 jquery 或更新数据表模型

【讨论】:

    猜你喜欢
    • 2020-08-18
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 2012-01-25
    • 1970-01-01
    相关资源
    最近更新 更多