Using Array of object when loading from javascript array and not ajax

Using Array of object when loading from javascript array and not ajax

billpullbillpull Posts: 11Questions: 0Answers: 0
edited January 2013 in General
I am trying to basically combine these two examples and load an array of objects directly into aaData from a variable. Not an Ajax source.
http://www.datatables.net/release-datatables/examples/data_sources/js_array.html
http://www.datatables.net/release-datatables/examples/ajax/objects.html

trying to set sAjaxSource to variable http://live.datatables.net/utecax/edit#

trying to set aaData to variable http://live.datatables.net/iyavud/5/edit

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    You need to tell DataTables which object property belongs in each column using mData: http://live.datatables.net/iyavud/7/edit .

    See also: http://datatables.net/blog/Extended_data_source_options_with_DataTables and the Ajax example you linked to :-)

    Allan
  • billpullbillpull Posts: 11Questions: 0Answers: 0
    Thanks. As a followup the reason I wanted to use the objects was I am using a date filter and want to use it on multiple tables but the index of the column I am filtering on will be different so I want to use something like aData.date instead of aData[3] but in my filtering function with the Object Array my aData becomes an array again. Any way to get around this.

    [code]
    $.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {
    var iMin = document.getElementById('start-datepicker').value;
    var iMax = document.getElementById('end-datepicker').value;

    // Create Minimum Date Object
    var iMinDate = new Date(iMin);

    // Create Maximum Date Object
    var iMaxDate = new Date(iMax);

    // Create Date Column Object
    var iDateStr = aData.date;
    var iDate = new Date(iDateStr);

    if ( iMinDate < iDate && iDate < iMaxDate )
    {
    return true;
    }
    return false;
    }
    );
    [/code]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Hmmm - annoyingly not :-(. This is the code in DataTables that causes the problem:

    [code]
    var bTest = afnFilters[i](
    oSettings,
    _fnGetRowData( oSettings, iDisIndex, 'filter', aiFilterColumns ),
    iDisIndex
    );
    [/code]

    It is creating an array from the current data, which I think is wrong. I've flagged this post to have this fixed as part of the 1.10 development. It should either pass in the original data source (which will be much faster), or pass in the original data source as a new parameter - which will be more compatible. I'll have a think about it!

    Allan
This discussion has been closed.