Controlling JSON generated by DataTables

Controlling JSON generated by DataTables

Douglas HanleyDouglas Hanley Posts: 2Questions: 0Answers: 0

Hey,

I have a table that is populated by Ajax via a GET request. JSON that is returned from GET is shown below:

{"data":[{"Id":1,"Cluster":1,"Customers":[0,1]},{"Id":0,"Cluster":0,"Customers":[0,1,2]}]}

As can be seen the data consists of ints and int arrays. I use JSON.stringify to generate JSON during a POST for adding a new row to the table. The JSON produced by Editor is:

{"data":{"0":{"Id":"","Cluster":"4","Customers":"[4,5]"}},"action":"create"}

As you can see it's generating string values where I'd expect int values. Is this expected behaviour of stringfy or am I not telling Editor enough about column types.

Thanks,

Douglas.

Replies

  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin

    Hi Douglas,

    The issue is caused by the fact that the values being edited are put into an HTML input element. When read back the values are always strings since they have no type structure.

    What you can do is use fields.getFormatter to define a function that will manipulate the value read back from the form though. You could use it to parseFloat() for example.

    Allan

  • Douglas HanleyDouglas Hanley Posts: 2Questions: 0Answers: 0

    Thanks Allan. Makes sense.

Sign In or Register to comment.