Loading ...
Sorry, an error occurred while loading the content.

JSON options for Dropdown select in DataTable

Expand Messages
  • lasse_yui
    Hi, Suppose you want to have some dropdown options delivered via JSON for your datatable. I cannot find a way this can be done with varying dropdown content.
    Message 1 of 1 , Sep 4, 2008
    View Source
    • 0 Attachment
      Hi,

      Suppose you want to have some dropdown options delivered via JSON for your datatable. I
      cannot find a way this can be done with varying dropdown content. Only two other options
      are either static in column definition or from JS_ARRAY. So I looked at declaring
      formatDropdown again. However, I found it smart to create a new function and call its
      "parent" function like so:

      var formatMultiDropdown = function(el, oRecord, oColumn, oData) {

      oColumn.dropdownOptions = oData.dropdownOptions;

      YAHOO.widget.DataTable.formatDropdown(el, oRecord, oColumn, oData);
      }

      The associated column definition looks like this:

      {key:"worksheets", formatter:formatMultiDropdown, label:"Worksheets"}


      Then just add the dropdowOptions object to the JSON like so:

      {
      "recordsReturned":2,
      "totalRecords":"2",
      "startIndex":0,
      "sort":"name",
      "dir":"desc",
      "sheets":[
      {
      "id":"31",
      "date":"08\/04\/2008",
      "name":"Worksheet1.xls",
      "worksheets":
      {
      "dropdownOptions":[{
      "text":"Sheet1","value":0},
      {"text":"Sheet2","value":1},
      {"text":"Sheet3","value":2}
      ]}
      },
      {
      "id":"32",
      "date":"09\/04\/2008",
      "name":"Worksheet2.xls",
      "worksheets":
      {
      "dropdownOptions":[{
      "text":"Budget 2008",
      "value":0}]
      }
      }
      }
      ]
      }


      I found this useful. If you know of a smarter way to achieve the same thing, do let me
      know.

      /Lasse
    Your message has been successfully submitted and would be delivered to recipients shortly.