This is a migrated thread and some comments may be shown as answers.

foreing key in a grid

0 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
diego
Top achievements
Rank 1
diego asked on 08 Aug 2012, 12:59 PM
<div id="grid"></div>


<script>
    $
(document).ready(function () {
        dataSource
= new kendo.data.DataSource({
            transport
: {
                read
: {
                    url
: '@Url.Action("GetCityList", "City")',
                    dataType
: "json",
                    type
: "GET",
                    contentType
: "application/json; charset=utf-8"
               
},
                create
: {
                url
: '@Url.Action("create", "City")',
                type
: "Post"
           
},
                parameterMap
: function (data, operation) {
                   
if (operation != "read") {
                       
var result = {};

                       
for (var i = 0; i < data.models.length; i++) {
                           
var ciudad = data.models[i];

                           
for (var member in ciudad) {
                                result
["ciudades[" + i + "]." + member] =                        ciudad[member];
                           
}
                       
}
                       
return result;
                   
}
               
}


           
},
            batch
: true,
            pageSize
: 30,
            schema
: {
                model
: {
                    id
: "id",
                    fields
: {
                        id
: { editable: false, nullable: true },
                        descripcion
: { validation: { required: true} },
                       
DepartamentName: { field: "DepartamentName" },
                   
}
               
}
           
}
       
});

        $
("#grid").kendoGrid({
            dataSource
: dataSource,
            navigatable
: true,
            pageable
: true,
            height
: 400,
            toolbar
: ["create", "save", "cancel"],
            columns
: [
               
"descripcion",
           
{ field: "DepartamentName", title: "Name Departament", editor: categoryDropDownEditor, width: 150 },
               
{ command: "destroy", title: "&nbsp;", width: 110}],
            editable
: true
       
});
   
});

</script>

<script>

    function categoryDropDownEditor
(container, options) {

        $
('<input data-text-field="name" data-value-field="name"  data-bind="value:' + options.field + '"/>')
                       
.appendTo(container)
                       
.kendoDropDownList({
                            autoBind
: false,
                            dataSource
: {
                                type
: "json",
                                transport
: {
                                    read
: {
                                        url
: '@Url.Action("GetDepartament", "city")
                                           
}
                               
}
                           
}
                       
});
   
}
           
</script>

it show me ok but my problem is that when It hit to my action create it give me the name of the departament not the id

and when i change my function this part to this

 $('<input data-text-field="name" data-value-field="name"  data-bind="value:' + options.field + '"/>')

 $
('<input data-text-field="name" data-value-field="id"  data-bind="value:' + options.field + '"/>')

with it show me fine in my action I get the id but in my grid when I choose in my dropdown a departament in the grid it show me the id (so is no the behavior I want)

how can I do to work this? I guees is in the bind part..

No answers yet. Maybe you can help?

Tags
Grid
Asked by
diego
Top achievements
Rank 1
Share this question
or