mydea / handsontable-chosen-editor

Use a chosen select field in a Handsontable.
http://mydea.github.io/handsontable-chosen-editor/
MIT License
63 stars 36 forks source link

ajax json data #2

Open cpolcino opened 8 years ago

cpolcino commented 8 years ago

Hi, it is possible to use ajax call to get json data? thanks a lot

mydea commented 8 years ago

The way this is implemented right now is that you would need to load all data before loading the table.

Rolok commented 8 years ago

First, off, let me say this makes handsontable gorgeous.

I'm fine with loading all the data before loading the table -- but don't know how to go about doing that.

I've tried using a hard coded variable in place of the values for data: in the chosenOptions, but to no avail. The list of values works fine as a literal string. I've tried putting a variable with just the id and label within the square brackets. I've tried including the square brackets in the variable. I've tried JSON.stringify(test). Is there any way to do this so that at load time I can set a list of values for the value list? I don't want to modify the list during usage, just at load I want to give it the values needed.

mydea commented 8 years ago

Doesn't the example from https://github.com/mydea/handsontable-chosen-editor work for you? E.g.:

chosenOptions: {
  data: [
    {
      id: "SPOT",
      label: "Spot"
    }, {
      id: "AFLOAT",
      label: "Afloat"
    }, {
      id: "PREORDER",
      label: "Preorder"
    }
  ]
}
Rolok commented 8 years ago

Yes, that example works wonderfully. However, what I was trying to do was to have those values be represented by a variable. Something that could be loaded before everything else and then used.

I worked more with it this morning. My struggle was getting the array of objects together. A simplified final example of my data that worked is here.

var myListOfValuePairs = [{ id:"299", label: "Accent Tables"},{ id:"248", label: "Accessories"}]

chosenOptions: { multiple: true, data: myListOfValuePairs

Thank you for responding, and hopefully this helps anybody else that comes along.