DataTables的自动填充扩展,输入元素不起作用 [英] DataTables' Autofill extension with input elements not working

查看:143
本文介绍了DataTables的自动填充扩展,输入元素不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 dataTables 插件自动填充扩展程序。它基本上允许您通过向上或向下拉列来复制单元格(右下角)。在我的项目中工作正常。

I am using the dataTables plugin with the AutoFill extension. It basically allows you to copy a cell by pulling the cross (bottom-right of it) up or down the column. This works fine in my project.

当我尝试复制单元格中的输入时,它将清除所选的输入。阅读文档,似乎旧版本的插件能够复制单元格中的输入,只需添加一个小的脚本。从当前文档,通过查看写入选项,默认情况下,我正在寻找的行为应该是可能的:

However, when I try to copy an input inside of a cell, it clears the selected inputs. Reading the docs, it seems that the older version of the plugin enables the copying of inputs inside cells, just by adding a small script. From the current doc, by looking at the write option, the behaviour I am looking for should be possible by default:


这个回调是fnRead的推论,提供了一种方法
自定义自动填充如何将计算的填充值写入给定单元格。
默认情况下,AutoFill将在输入中设置值,如果找到,则在单元格中选择元素
,否则将将该值设置为HTML。

This callback is the corollary of fnRead, providing a method to customise how AutoFill writes a calculated fill value to a given cell. By default AutoFill will set the value in an input or select element in a cell if found, otherwise it will set the value as HTML.

事情是,当一个输入有一个初始值时,复制工作。但是,当添加/编辑该值时,它将复制上一个值。它尝试添加读写功能选项,但是它们从不被调用(见小提琴)。

The thing is, when an input has an initial value, the copying works. But when adding/editing the value, it copies the previous one. It tried to add the read and write function options, but they are never called (see fiddle).

这是一个 jsFidle ,正好复制了我的问题: / p>

Here's a jsFidle reproducing exactly my issue:


  1. 将row.1 col.1拖到row.2 col.1 - >作品

  2. 编辑row.1 col.1的值,并重复步骤1 - >返回上一个值

  3. 在row.1 col.2中输入值并将其拖动 - >重置没有复制

似乎值属性永远不会更新。

It seems that the value attribute is never updated.

推荐答案

您需要使用读取写入回调来检索和设置< input> 元素。

You need to use read and write callbacks to retrieve and set values of <input> elements.

同样,AutoFill似乎试图默认增加值。我不得不添加 step 回调来覆盖此行为。

Also it seems that AutoFill tries to increment values by default. I had to add step callback to override this behavior.

new $.fn.dataTable.AutoFill(table, {
    "columnDefs": [{
        "read": function (cell) {
            return $('input', cell).val();
        },
        "write": function (cell, val) {
            return $('input', cell).val(val);
        },
        "step": function ( cell, read, last, i, x, y ) {
           return last === undefined ? read : last;
        },        
        "targets": [0,1,2] // Use "_all" to target all columns
    }]
});

请参阅这个JSFiddle 进行代码和演示。

See this JSFiddle for code and demonstration.

这篇关于DataTables的自动填充扩展,输入元素不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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