AutoFill - How can you copy only the text portion of a cell when dragging?

AutoFill - How can you copy only the text portion of a cell when dragging?

glendersonglenderson Posts: 231Questions: 11Answers: 29

I'm trying to use AutoFill on a table.

Each cell, contains a <span class={some class} id={some id} onclick={some function} oncontextmenu={some different function}>my value</span>. I only want to copy / autoFill the "my value" portion, and not the entire contents of the <td>.

I can easily read the value of the cell via the "read" option

"read": function(cell) {return $(cell).text()}

But, I cannot figure out the "write" / "step" methods that would allow me to only replace the .text() portion of the cell I'm writing to.

"write": function(cell, val) {return $(cell).text(val)}

The basic idea is that I have 12 cells, and the user can fill in cells doing a "copy right" type of command, highlight a cell, drag them right, let go, and those cells are populated with the first cells value, but not the <span> contents as they are all unique. My tables are all populated via JSON (because of ajax updates) on a callback ajax method so I cannot put the various span elements (id, on events, etc.) on the <td> itself.

I like the visual presentation of the AutoFill extension, just looking for a way to replace only the .text() of the cell (without any increments to numerical values also).

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    The solution was to set the text of the first child of the cell.
    Something like
    return $(cell).children().first().text(val) in the write function.

This discussion has been closed.