Lazy DropDownList: custom template
Components / Samples
Description
DropDownList
widget allows you to customize the item's display using a jQuery template,
which will be enclosed in a <script type="text/x-kendo-template" />
(so you can use the "\n
" character to properly format the template).
For a DropDownList
, the properties used in the template text (ie: #: data.name #
) should be prefixed by "data.
" and should be identified in the list returned by IJQueryTemplate#getTextProperties()
, without "data.
".
@Override protected IJQueryTemplate newTemplate() { return new IJQueryTemplate() { private static final long serialVersionUID = 1L; @Override public String getText() { return "<i>#: data.name #</i>"; } @Override public ListgetTextProperties() { // should be specified, unless already part of the IChoiceRenderer return Arrays.asList("name"); } }; }
Since
wicket-kendo-ui-7.1.0Licensing
Kendo UI "Core" is Apache License 2.0 licensed, starting from version 2014.1.416.Prior to version 2014.1.416, Kendo UI "Web" was licensed under GPLv3.
A pro version - with a commercial license - is also available, it provides additional widgets (see http://docs.telerik.com/kendo-ui/intro/supporting/list-of-widgets)
To be able to use it, you need to change the
ResourceReference
with kendo.all.min.js
See also
[howto]-change-resource-referencesSources
- Java
- HTML
- CSS
package com.googlecode.wicket.jquery.ui.samples.kendoui.dropdown; import java.util.Arrays; import java.util.List; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.model.Model; import com.googlecode.wicket.jquery.core.template.IJQueryTemplate; import com.googlecode.wicket.jquery.ui.samples.data.bean.Genre; import com.googlecode.wicket.jquery.ui.samples.data.dao.GenresDAO; import com.googlecode.wicket.kendo.ui.form.button.AjaxButton; import com.googlecode.wicket.kendo.ui.form.button.Button; import com.googlecode.wicket.kendo.ui.form.dropdown.lazy.DropDownList; import com.googlecode.wicket.kendo.ui.panel.KendoFeedbackPanel; public class TemplateDropDownPage extends AbstractDropDownPage { private static final long serialVersionUID = 1L; public TemplateDropDownPage() { Form<Void> form = new Form<Void>("form"); this.add(form); // FeedbackPanel // final KendoFeedbackPanel feedback = new KendoFeedbackPanel("feedback"); form.add(feedback); // DropDownList // final DropDownList<Genre> dropdown = new DropDownList<Genre>("select", new Model<Genre>(), GenresDAO.all()) { private static final long serialVersionUID = 1L; @Override protected void onInitialize() { super.onInitialize(); this.setListWidth(200); } @Override protected IJQueryTemplate newTemplate() { return new IJQueryTemplate() { private static final long serialVersionUID = 1L; @Override public String getText() { return "\n<table style='width: 100%'>" + "\n <tr>" + "\n <td>" + "\n <img src='#: data.coverUrl #' width='50px' />" + "\n </td>" + "\n <td>" + "\n #: data.name #" + "\n </td>" + "\n </tr>" + "\n</table>"; } @Override public List<String> getTextProperties() { return Arrays.asList("name", "coverUrl"); } }; } }; form.add(dropdown); // Buttons // form.add(new Button("submit") { private static final long serialVersionUID = 1L; @Override public void onSubmit() { TemplateDropDownPage.this.info(dropdown); } }); form.add(new AjaxButton("button") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { TemplateDropDownPage.this.info(dropdown); target.add(feedback); } }); } private void info(DropDownList<Genre> dropdown) { Genre choice = dropdown.getModelObject(); this.info(choice != null ? choice : "no choice"); } }
<!DOCTYPE html> <html xmlns:wicket="http://wicket.apache.org"> <head> <wicket:head> <title>Wicket Kendo UI: drop-down (custom template)</title> </wicket:head> </head> <body> <wicket:extend> <div id="demo-panel"> <form wicket:id="form"> <input wicket:id="select" /> <button wicket:id="submit" type="submit">Submit</button> <button wicket:id="button">Ajax Button</button> <br/><br/> <div wicket:id="feedback" style="width: 360px;"></div> </form> </div> </wicket:extend> </body> </html>