Initialize from ajax and fnGetPosition

Initialize from ajax and fnGetPosition

deslyxiadeslyxia Posts: 3Questions: 0Answers: 0
edited October 2013 in General
Im working on populating a dataTable using ajax. I have created a method that works in my code but it is not the "reccomended" method shown in the examples here. On top of that I am trying to also use the get position function from the api and I am also getting issues.

If I populate the dataTable using my ajax method it works ... it populates ... BUT the issue is that no matter how i try to initialize a var called oTable when i get into my .on("click') function in jquery i always get an error that oTable is undefined ....

I thought that it may be because of how i was actually populating the table thru ajax so i tried to switch to the model shown in the examples .... BUT i always wind up with an error that "k is not defined" somewhere in the jQuery.DataTable.js file

Im not quite sure where to go with these issues any help would be appreciated.

The code below Works ... I need to also get the commented out click functionality to work (again please note that the initial alert box does pop up on click)

Also i know that somewhere i should be setting a var called oTable but im not sure exactly where and all the combinations ive tried do not work out correctly.

[code]

$(document).ready(function () {


function populateTable(json){
$('#example').dataTable(json);
};

function getCampaigns() {
$.ajax({
url : '/adktest/getcampaigns',
}).done(function(response) {
populatetable(response);
}).error(function(jqxhr, textstatus, errorthrown) {
alert("didn't work");
});
};

getCampaigns();

$('#example').on('click','tr', function (e) {
// Get the position of the current data from the node
var aPos = oTable.fnGetPosition(this);

// Get the data array for this row
var aData = oTable.fnGetData(aPos[0]);

// Update the data array and return the value
aData[aPos[1]] = 'clicked';
this.innerHTML = 'clicked';
});
});


[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I don't see `oTable` being defined anywhere in your code - so it looks to me that the error about oTable not existing is probably correct!

    Try adding:

    [code]
    var oTable = $('#example').dataTable();
    [/code]

    as the first line in your click event handler. Or save the reference from the original initialisation.

    Allan
This discussion has been closed.