javascript - DataTables' Autofill extension with input elements not working -
context
i using datatables plugin autofill extension. allows copy cell pulling cross (bottom-right of it) or down column. works fine in project.
problem
however, when try copy input inside of cell, clears selected inputs. reading docs, seems older version of plugin enables copying of inputs inside cells, adding small script. current doc, looking @ write
option, behaviour looking should possible default:
this callback corollary of fnread, providing method customise how autofill writes calculated fill value given cell. default autofill set value in input or select element in cell if found, otherwise set value html.
the thing is, when input has initial value, copying works. when adding/editing value, copies previous one. tried add read , write function options, never called (see fiddle).
code
here's jsfidle reproducing issue:
- drag down row.1 col.1 row.2 col.1 -> works
- edit value of row.1 col.1 , repeat step 1 -> goes previous value
- enter value in row.1 col.2 , drag down -> resets values without copying
it seems value attribute never updated.
you need use read
, write
callbacks retrieve , set values of <input>
elements.
also seems autofill tries increment values default. had add step
callback override 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" target columns }] });
see this jsfiddle code , demonstration.
Comments
Post a Comment