Closed ammar91 closed 8 years ago
tableToJson
was not made to support calling directly on objects. The only way to use table to json is with a selector: $('#schedules table'). tableToJSON()
If you update this Plunker template with your HTML and tell me what you are expecting your JSON to look like, then I can try to help: http://plnkr.co/edit/iQFtcEEZkvsMJ2UqcrlW
Thanks for your attention. I updated plunkr and that is how my html look like. But with this markup I can't convert it to json as it produces empty strings..
Please provide me with the link of the updated plunker
TableToJSON is not meant to work with <input>
tags. In the next version, I might add some support for data manipulation - but there are no immediate plans. Please refer to this StackOverflow answer on how to build a javascript object to represent your table of inputs: http://stackoverflow.com/a/18133864/912563
Actually, that is what the textExtractor
is for (demo)
$('#run').click( function() {
var table = $('#students').tableToJSON({
textExtractor : function(cellIndex, $cell) {
// get value from the input inside table cells;
// if empty or non-existant, get the cell text
return $cell.find('input').val() || $cell.text();
}
});
alert(JSON.stringify(table));
});
Oh fantastic, thanks @Mottie
I have a table in my view but that's all contain input inside td element. If I directly try to call tableToJSON on my table, the json it produce contain empty values..So what I am trying to do is to clone the actual table and change the input field to plain text and then call tableToJSON on that clone variable but it produces empty array.. But If I use the actual table it works but that actually make changes visually as well which I really don't want...My code looks like this: