Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript Variables

Status
Not open for further replies.

Chalupabatman

Programmer
Oct 18, 2019
2
0
0
US
Hi - I am declaring the variable table but when my page loads I am getting the error: Uncaught TypeError: Cannot read property 'row' of undefined

How should I change my code so this functions as desired?

Code:
<script>
	var table;
    $(document).ready(function () {
    $("#btnTapCountCheck").click(function () {
        table = $('#data').DataTable({ 
            dom: 'Bfrtip',
            buttons: [ 'copy', 'csv', 'excel', 'pdf', 'print' ],
            "ajax": function (data, callback, settings) {
                $.ajax({
                    url: '[URL unfurl="true"]https://localhost:44328/api/tap-count',[/URL]
                    dataType: "JSON",
                    success: function (data) {
                            var o = {"data":[]};
                            for(var i in data.data)
	                        {
	                            var row = [data.data[i].location,data.data[i].tapCount];
	                            o.data.push(row);
                            }
                            callback(o);
                    }
                })
            }
        }
    });
	$("#AddRow").click(function () {
        table.row.add( [] ).draw(false);
    } );
 
    $('#AddRow').click();
    });

});
</script>
 
what do you do get in the variable data when you place a break point on the line that gets the success side of the query? are you getting json? or is it a string of json that needs to be turned back into an object?
does data have a data collection?

I would expect some time in the developer tools (F12) of your browser would answer a lot of your questions about why you are getting nothing for your row.
 
@NoCoolHandle - I get JSON returned. If I comment out the #AddRow lines of code, there are no errors and everything works as I expect.

I know C#, but am trying to get fancy and on a button click add a empty row to Jquery DataTables
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top