alfajango / jquery-dynatable

A more-fun, semantic, alternative to datatables
http://www.dynatable.com
Other
2.77k stars 361 forks source link

dynatable.recordes returns undefined #134

Open maysamsh opened 10 years ago

maysamsh commented 10 years ago

I'm using such code to update my dynatable:

function gettableupdates(){        
            $.getJSON('/app/transactions/get_transactions/',
            function (data) {                
                var dynatable = $('#myTable').data('dynatable');                
                dynatable.records.updateFromJson({records: data});
                dynatable.records.init();               
                dynatable.process();                
            });        
        }

But when I log dynatable.records it says it's undefined.

hamburger123456 commented 10 years ago

I had this problem also. The issue was: The table.header (title) has to match to the contend of the json-file.

drouillard commented 10 years ago

Hi @maysamsh

Can you try the following?

$('#my-ajax-table').dynatable({
  dataset: {
    ajax: true,
    ajaxUrl: '/dynatable-ajax.json',
    ajaxOnLoad: true,
    records: []
  }
});

http://www.dynatable.com/#json-from-ajax

mhnatiuk commented 9 years ago

This issue persists. Making changes to the REST Api that responds to dynatable requests is a bad idea. Can someone explain how to work around this?

krokofant commented 9 years ago

This seems to be because the default column name translation is to camelcase. The problem arises when a record property key like "LargeLetters" in transformed to "largeLetters". When DynaTable tries to return the property/cell value it tries to get record[largeLetters] instead of record[LargeLetters].

This can be solved by creating a custom textTransform.

$.dynatableSetup({
    table: {
        defaultColumnIdStyle: 'noStyle'
    }
});

// And on the table
$table.bind('dynatable:preinit', function(e, dynatable) {
    dynatable.utility.textTransform.noStyle = function(text) {
        return text;
    };
})

I don't really get why this lib uses camelcase conversion by default.

markdwags commented 8 years ago

Thanks @krokofant this corrected the issue I was having with data being returned via JSON and not matching camelcase.