Properties enclosed by quotes: how to fix this?

Properties enclosed by quotes: how to fix this?

svierkantsvierkant Posts: 33Questions: 2Answers: 0
edited April 2013 in General
I'm using a framework to configure the properties for Datatables. I'm using PHP and Twig. I'm building an array, containing all data (such as aaData and aoColumnDefs) and configuration (sorting, columns, etc.). The problem I'm facing is that json_encode($config) returns the JSON representation of a value, enclosed by quotes.

DataTables expects a non-quotes value, but this is what my script returns:
[code]
$('#example').dataTable({"aoColumnDefs":[{"sType":"numeric","sWidth":"100px","aTargets":[4,5]});
[/code]
My problem: 'aoColumnDefs' has to be enclosed by quotes, but 'sType' of 'sWidth' may not be enclosed by quotes.

How can I fix this?

Replies

  • svierkantsvierkant Posts: 33Questions: 2Answers: 0
    I found the problem:

    I removed
    [code] "fnStateSave": function (oSettings, oData) {
    localStorage.setItem( 'DataTables_'+window.location.pathname, JSON.stringify(oData) );
    },
    "fnStateLoad": function (oSettings) {
    return JSON.parse( localStorage.getItem('DataTables_'+window.location.pathname) );
    },
    [/code] and now it works! I don't know why this was the problem?
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Not sure why that would be a problem - it looks like it should work okay to me. If you are able to post a test page showing the issue I will be able to debug it further.

    Thanks,
    Allan
This discussion has been closed.