lightswitch05 / table-to-json

Serializes HTML tables into JSON objects.
http://lightswitch05.github.io/table-to-json/
MIT License
756 stars 172 forks source link

Adding Rows, New Rows ignored #25

Closed erichiller closed 8 years ago

erichiller commented 8 years ago

I was looking for the ability to add rows on the fly, so I wrote a simple button & related function. The elements are added, everything shows in the DOM correctly, no errors in the console. But the elements are unable to be edited as the other elements / preexisting are. I am unsure if this is user error (-- me) or if this is a bug or just feature that is lacking? Here is my code:

$(function(){
    $( ".addRow").click( function(){
        var target = this.id.substring(this.id.indexOf("_")+1);
        var table = document.getElementById("table_" + target);
        var row = table.getElementsByTagName('tbody')[0].insertRow(-1);
        var tdCount = table.firstElementChild.firstElementChild.childElementCount;
        for(i = 0; i < tdCount; i++){
            var cell = row.insertCell(i);
            var newText = document.createTextNode("testText");
            cell.appendChild(newText);
        }
    })
})  

<button class="button addRow" id="addrow_tablename">Add Row</button>

Thanks for the work, it is much appreciated! Great project.

lightswitch05 commented 8 years ago

@variab1e I don't see table-to-json anywhere in your code. Please update this Plunker with an example of what you are doing and how it relates to table-to-json: http://plnkr.co/edit/iQFtcEEZkvsMJ2UqcrlW

erichiller commented 8 years ago

@lightswitch05 I can do you one better! I just posted my project that used your code late last night! I commented out the "add row" code for now add just added a single blank row, but everything I was using is still there.

See https://github.com/variab1e/dnsmasq-qpkg/blob/master/shared/web/index.php#L229

Let me know if it doesn't make sense, I'll write everything up if so!

lightswitch05 commented 8 years ago

@variab1e Well now I see your code - but I don't have an easy way to run it without starting up my own php server. If you update this Plunker to show what your final HTML looks like and the javascript you are using - then I'll be able to help out. Starting up my own server is a bit more work then I'm willing to do. http://plnkr.co/edit/iQFtcEEZkvsMJ2UqcrlW?p=preview

erichiller commented 8 years ago

@lightswitch05 So I have it posted and working -- http://plnkr.co/edit/iQFtcEEZkvsMJ2UqcrlW?p=preview

In hindsight here, I think I am not the brightest bulb, and am not sure how related it is to table-to-json either. I guess I was too deep in it. I did figure it out though. Just thinking it through is all I needed. It may help someone else? I suppose it is somewhat related, being able to edit and add rows right?

Anyways thanks for humoring me. -Eric

lightswitch05 commented 8 years ago

I'm you figured it out