Search code examples
phpjqueryajaxhandsontable

Handsontable: How to post the data as an associative array


Using handsontable, you are supposed to be able to post with ajax by including the data like so:

    data:  {data: myHandsOnTable.getData()},

see getData()

But this posts the data as an indexed array, eg:

[
  0=> "data"
  1=> "moreData"
]

How would I go about posting the data as an associative array with the column indexes as the keys? eg:

   [
      "name"=> "data"
      "email"=> "moreData"
    ]

Idealy there would be a built-in way to do this, eg something like: getDataAssoc() that would add the column key as the key. Rather than having to add a function to loop over and rebuild the data prior to posting it


Solution

  • If you upgrade to a later version of handsontable, you can use the getSourceData method. That should get you the data in the format you're looking for. It returns your original data object, and any changes that occurred in the table will be applied.