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

Make Complex Object Not Editable

6 Answers 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 18 Jun 2014, 01:49 PM
Here is my grid definition...

<div id="grid-members" data-role="grid"
                 data-sortable="true"
                 data-scrollable="false"
                data-editable="true"
                 data-columns='[
                                    { field: "Contact.FullName", title: "Name" },
                                     { field: "IsSomething", title: "Is Something" },
                                    { field : "StartDate", title: "Start Date", width: "120px" },
                                  ]'
                 data-bind="source: Contacts"
                data-source="{schema: {model: {fields: {Contact.FullName : {editable:false}, IsSomething : {type : 'boolean'}, StartDate: {type: 'date'}}}}}"
                ></div>

My object is something like...
{
   Contact : { FullName : 'My Name'},
   IsSomething : true,
   StartDate : '1/1/2014'
}

How can I tell my Contact.FullName field to be not editable?

Thanks
Joe

6 Answers, 1 is accepted

Sort by
0
Accepted
CS
Top achievements
Rank 2
answered on 18 Jun 2014, 02:15 PM
You could go and use a template instead maybe
data-columns='[{field: "Contact", title: "Name", template: "#=Contact.FullName#}]
data-source="{schema: {model: {fields: {Contact : {editable:false}}}}"
0
Joe
Top achievements
Rank 1
answered on 18 Jun 2014, 02:32 PM
Thank you so much.  That works almost perfectly.  The only issue now, is that my sort is broken since it's sorting on the object instead of the FullName.  Any ideas on how to search on the FullName instead of the object?

Thanks again,
Joe
0
Petur Subev
Telerik team
answered on 20 Jun 2014, 11:45 AM
Hello Joe,

Sorting/Filtering/Grouping is working over the field that you bound the column to, this means that if you want to filter over that fullname property you need to bind to column to it.

e.g.

data-columns='[{field: "Contact.FullName", title: "Name", template: "#=Contact.FullName#}]


Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Joe
Top achievements
Rank 1
answered on 20 Jun 2014, 12:44 PM
Ok, but that brings be back to my original problem.  If I bind to my Contact.FullName property, how can I tell the grid that column is not editable?
0
Accepted
CS
Top achievements
Rank 2
answered on 20 Jun 2014, 12:54 PM
You could also try this and make a custome compare function described here KendoUI Grid: custom sorting algorithms.
{
    field   : "Contact",
    width   : 200,
    title   : "Name",
     template: "#=Contact.FullName#,
    sortable: {
        compare: function (a, b) {
            return a.FullName > b.FullName;
        }
    }
}
No idea if that works, but it might be worth a try.
0
Joe
Top achievements
Rank 1
answered on 20 Jun 2014, 04:06 PM
YES!  Thank you.  That was exactly what I needed.  I just needed to change a.FullName to a.Contact.FullName and b.FullName to b.Contact.FullName in your solution.   

Thanks again,
Joe
Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
CS
Top achievements
Rank 2
Joe
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or