Author Topic: Drop down select for object  (Read 3362 times)

knobbs

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 8
    • View Profile
Drop down select for object
« on: February 11, 2016, 02:27:51 am »
I have a grid where the data model has a complex object, for example:

var item = {
  ActivityType: { Id: 1, Name: "Cold Call" }
};

When I create an editor with a select item, like this:

    editor: {
        type: 'select',
        valueIndx: "Id",
        labelIndx: "Name"
        options: [ { Id: 1, Name: "Cold Call" }, { Id: 2, Name: "Email"}, { Id: 3, Name: "Visit" } ]
    };

I cannot get the value to save to the complex object in the data item. Here is a jsfiddle demonstrating what I mean--The Activity column will not update, but the description will because it is not complex.

I attempted to add a getData handler like this:

        getData: function (ui) {
            var val = ui.$cell.find("select").val();
            var txt = ui.$cell.find("select").find("option:selected").text();

                 return { Id: val, Name: txt };
        }

but it does not work (and throws an error).

Can anyone help?

Thanks in advance.


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6296
    • View Profile
Re: Drop down select for object
« Reply #1 on: February 11, 2016, 10:31:10 am »
You have mentioned jsfiddle. Could you please share the url to jsfiddle.

There is only limited support for complex or nested objects. I've created this jsfiddle that shows how to use complex objects by using

1. dataType: 'object'

2. custom column render

3. editor.getData callback:

http://jsfiddle.net/u0c6cakw/3/
« Last Edit: February 11, 2016, 05:51:19 pm by paramquery »

knobbs

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Drop down select for object
« Reply #2 on: February 11, 2016, 07:10:57 pm »
Oops!  I am sorry-- here is my fiddle:

http://jsfiddle.net/p4qnweun/2/

I will look at your reply and see if I can get that to work.

Thank you!

knobbs

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Drop down select for object
« Reply #3 on: February 11, 2016, 09:39:26 pm »
The solution provided worked great.  Thank you for your prompt response!