sAjaxSource removes attributes and event listeners from table cells

sAjaxSource removes attributes and event listeners from table cells

flyingbuddhaflyingbuddha Posts: 2Questions: 0Answers: 0
edited September 2010 in General
Hi all,

I have a table with the following example markup:
[code]

Hello world


Name
Price




Eggs
3.99


Chips
1.99



[/code]

When I use sAjaxSource to return data from the server, I loose all attributes on the table cells and any events assigned to the data within those cells (i.e. javascript click events), i.e.
[code]

Hello world


Name
Price




Eggs
3.99


Chips
1.99



[/code]

This happens exclusively when I use sAjaxSource, if I start up without this parameter, the classnames', etc. remain intact.

The data structure I return from the server is something like:
[code]
{
sEcho: 1
iTotalRecords: 11
iTotalDisplayRecords: 10
aaData: [
['Eggs', 3.99],
['Chips', 1.99]
]
}
[/code]

Am I doing something wrong or missing something?
Cheers for any replies.

Replies

  • flyingbuddhaflyingbuddha Posts: 2Questions: 0Answers: 0
    So I ended up doing something like this:
    [code]
    /**
    * rowCallback
    *
    * Reassigns and cleans classname's on cells when sAjaxSource is used
    *
    * @since Thu Sep 16 14:51:25 BST 2010
    * @access public
    * @author Mike Holloway
    * @link http://datatables.net/usage/callbacks
    * @param node [tr] "TR" element for the current row
    * @param array. [data] Raw data array for this row (as derived from the original HTML)
    * @param int [dtRowIndex] The display index for the current table draw
    * @param int [actualRowIndex] The index of the data in the full list of rows (after filtering)
    * @return node [tr] "TR" element for the current row
    */
    function rowCallback(tr, data, dtRowIndex, actualRowIndex)
    {
    var columns = this.aoColumns;
    var cells = $('td',tr);
    var i = 0;
    var needle = 0;
    var classes = [];

    for(; i -1){
    columnClassNames.splice(needle,1);
    }
    }

    // apply original structure classnames to this cell
    if(columnClassNames.length) $(cells[i]).addClass( columnClassNames.join(' ') );

    // remove empty class attributes
    if($(cells[i]).get(0).className.replace(/\s+/,'') === '') $(cells[i]).removeAttr('class');
    }
    return tr;
    }
    [/code]
This discussion has been closed.