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

Treeview itemAction: how to set checked based on field in datasource?

3 Answers 295 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 03 Nov 2015, 01:43 AM

 If I have a treeview with .DataSource(d=>d.Model(....).Read(r=>r.Action(....)))

Can I use .ItemAction() to set item.checked based on a field provided in the DataSource?  How?

In the code below, what would I put in place of the bolded comment?

@( Html.Kendo()
       .TreeView()
       .DataTextField("Name")
       .Name("userPermissionsTree")

       .Checkboxes(cbxConfig => cbxConfig.Enabled(true)
                                         .CheckChildren(true)
                                         .Name("checkedNodes"))
       .DataSource(d => d.Model(m =>
                                {
                                    m.Field("enabled");
                                    m.Id("permissionId")
                                })
       .Read(read => read.Action("PermissionsTree_Read",
                                                   "SettingsUsers",
                                                   new {
                                                       userId = Model
                                                   })))
      .ItemAction(item=>item.Checked=    /*******set to true if field enabled is true**********/    )
      .Events(events => events
        .Check("onPrivilegeCheck"))
      )

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 05 Nov 2015, 08:35 AM
Hello,

The ItemAction method can only be used if the treeview is bound on the server. If the data is loaded via Ajax then you should set the checked field to true for the items returned from the server that should be checked.

Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Scott
Top achievements
Rank 1
answered on 05 Nov 2015, 06:11 PM

My question is how to do that, if ItemAction does not work.

 It appears that the Model in the DataSource does not allow for a checked field (see below).  So when/where/how would this be done?

.DataSource(d => d.Model(m =>
                         {
                             m.Field("enabled");
                             m.Id("permissionId");
                             m.checked("enabled"); // this is not available
                         })

0
Daniel
Telerik team
answered on 06 Nov 2015, 08:05 AM
Hello again,

There isn't a configuration option to set the checked field name. You should include a field named checked in the items. Another option is to set the fields from option via the Custom builder:
.DataSource(dataSource => dataSource.Custom()
    .Transport(transport => transport
        .Read(read => read
            .Action("Action", "controller")
        )
    )
    .Schema(schema=> schema
        .Model(model =>
        {
            m.Field("checked", typeof(bool)).From("enabled");
            m.Id("permissionId");
        })
    )
)
but note that the enabled field will not be available in the items with this approach. 

Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TreeView
Asked by
Scott
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Scott
Top achievements
Rank 1
Share this question
or