html - Using document.getSelection() to get data to array like document.getSelection().toString() does for strings -
i have table in angular js filtering. want have selected data in table in array rows[] of arrays cell[]. why cannot export table data. have tried document.getselection().tostring() class , .split failed elements in table might consist of more 1 word blanks in between.
is there way loop thru object document.getselection() , distinguish between rows , cells?
with data text, need array:
var txt = ''; if (document.getselection) { txt = document.getselection().tostring(); } else if (document.selection) { txt = document.selection.createrange().text; }
here object:
if (document.getselection) { txt = document.getselection(); } else if (document.selection) { txt = document.selection.createrange(); } console.log(txt)
selection { anchornode: , anchoroffset: 0, focusnode: , focusoffset: 3, iscollapsed: false, rangecount: 1, caretbidilevel: 0 }
actually answer quite easy. had use document.getselection().tostring() function , use split("/n") lines array, used split again separate elements tab added between column cells.
var tmp = []; var rows = []; var cells = []; tmp = txt.split("\n"); (var i=0; i<tmp.length; i++) { cells.length = 0; cells = tmp.split("\t"); rows.push(cells); }
Comments
Post a Comment