Author Topic: Bind Select editor to Object  (Read 4046 times)

jax

  • Newbie
  • *
  • Posts: 16
    • View Profile
Bind Select editor to Object
« on: June 23, 2014, 10:23:10 am »
I am rendering an object to a cell, and then binding a select editor with a list of strings. However, I would like to bind the select editor with a list of objects, the same type of object that is binded to the actual cell. Can this be done? Reason I want to do this is so that when the update goes back to the server with a new value, I can have the primary key id of the object instead of just the string value that I have now.

        var colM = [
            {
                title: 'Facility', width: 100, dataIndx: 'FacilityName', dataType: 'string',
                editor: {
                    type: 'select',
                    options: facilities,
                },
                render: function (ui) {
                    return ui.rowData['Facility']['Name'];
                }
            },

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Bind Select editor to Object
« Reply #1 on: June 23, 2014, 09:36:30 pm »
yes that can be done with the help of editor.getData callback :)

return an object containing both value & text of the option in select list in this callback.
« Last Edit: June 23, 2014, 09:40:46 pm by paramquery »

jax

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Bind Select editor to Object
« Reply #2 on: June 24, 2014, 06:25:31 am »
Can you point me to an example of this? I tried using the below where facilities is valid JSON data and the select list is empty

editor: {
                    getData: function () { return facilities },
                    type: 'select'
                }
« Last Edit: June 24, 2014, 06:37:35 am by jax »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Bind Select editor to Object
« Reply #3 on: June 24, 2014, 10:54:56 am »
I understand that you are trying to associate primary keys along with the string values in dropdown so that you receive primary keys when data is posted to the server.

It can be done in a number of ways.

I've updated this demo http://paramquery.com/pro/demos/editing_custom with a simple solution whereby primary keys are stored in data while string values are displayed in the view. Please check the code for ShipVia column.

let me know whether it fulfills your requirement.