ListBox
概要
機能
サンプル
検索結果:
SelectedIndex:
SelectedValue:
仮想化しきい値に対応する実際の要素の数値:
設定
説明
このサンプルは、ListBox コントロールの基本的な使用方法を示します。
CaseSensitiveSearch プロパティをtrueに設定した場合、検索では大文字と小文字が区別されます。
VirtualizationThresholdプロパティを使用すると、仮想化を有効または無効にできます。このプロパティのデフォルト値は非常に大きい数値であり、仮想化が無効になっていることを意味します。仮想化を有効にするには、値を0または正の数に設定します。ListBoxに多数のアイテム(たとえば1,000程度)が含まれている場合に、視覚化はパフォーマンスに大きな影響を与えます。
ソース
IndexController.cs
using MvcExplorer.Models;
using System.Collections.Generic;
using System.Web.Mvc;
namespace MvcExplorer.Controllers
{
public partial class ListBoxController : Controller
{
private readonly ControlOptions _optionModel = new ControlOptions
{
Options = new OptionDictionary
{
{"Case Sensitive Search",new OptionItem{ Values = new List<string> { "True", "False"}, CurrentValue = "False"}},
{"Virtualization Threshold",new OptionItem{ Values = new List<string> { "Disable" , "0" }, CurrentValue = "Disable"}}
}
};
public ActionResult Index(FormCollection collection)
{
IValueProvider data = collection;
_optionModel.LoadPostData(data);
ViewBag.DemoOptions = _optionModel;
ViewBag.Cities = Cities.GetCities();
return View();
}
}
}
Index.cshtml
@{
List<string> cities = ViewBag.Cities;
ControlOptions optionsModel = ViewBag.DemoOptions;
ViewBag.DemoSettings = true;
string vThreshold = optionsModel.Options["Virtualization Threshold"].CurrentValue;
}
<div>
<label>@Html.Raw(Resources.ListBox.Index_SelectAnItem)</label>
<div class="wj-input" style="margin: 5px 0px">
<input type="text" id="searchValue" class="wj-form-control" placeholder="@Html.Raw(Resources.ListBox.EnterTextSearch_Text0)" style="width:250px; height: 30px"/>
</div>
<div id="list" style="width:250px;height:200px"></div>
</div>
<p>
<b>@Html.Raw(Resources.ListBox.Index_SearchResult)<span id="lbSelResult"></span></b>
</p>
<p>
<b>@Html.Raw(Resources.ListBox.Index_SelectedIndex)<span id="lbSelIdx"></span></b>
</p>
<p>
<b>@Html.Raw(Resources.ListBox.Index_SelectedValue)<span id="lbSelVal"></span></b>
</p>
<p>
<b>@Html.Raw(Resources.ListBox.Index_VirtualizationThreshold)<span id="lbSelVThreshold"></span></b>
</p>
@section Scripts{
<script>
// selectedIndexChanged event handler
function selectedIndexChanged(sender) {
// set selectedIndex and selectedValue text
document.getElementById('lbSelIdx').innerHTML = sender.selectedIndex;
document.getElementById('lbSelVal').innerHTML = sender.selectedValue;
}
c1.documentReady(function () {
document.getElementById("searchValue").addEventListener("keyup", function (e) {
var listbox = wijmo.Control.getControl('#list');
listbox.selectedIndex = -1;
listbox._search = this.value;
listbox.selectedIndex = listbox._findNext();
var searchValue = document.getElementById("searchValue").value;
if (searchValue === '') {
document.getElementById('lbSelResult').innerHTML = null;
return;
}
var searchResult;
if ('@optionsModel.Options["Case Sensitive Search"].CurrentValue' === 'False') {
searchResult = listbox.itemsSource.items.filter(function (c) {
if (c.toLowerCase().indexOf(searchValue.toLowerCase()) == 0) return c;
});
} else {
searchResult = listbox.itemsSource.items.filter(function (c) {
if (c.indexOf(searchValue) == 0) return c;
});
}
document.getElementById('lbSelResult').innerHTML = searchResult.join(", ");
});
document.getElementById('lbSelVThreshold').innerHTML = document.getElementById("list").childNodes.length;
});
</script>
}
@(Html.C1().ListBox("#list")
.Bind(cities).SelectedIndex(0)
.OnClientSelectedIndexChanged("selectedIndexChanged")
.CaseSensitiveSearch(Convert.ToBoolean(optionsModel.Options["Case Sensitive Search"].CurrentValue))
.VirtualizationThreshold(vThreshold.Equals("Disable") ? int.MaxValue : int.Parse(vThreshold))
)
@section Settings{
@Html.Partial("_OptionsMenu", optionsModel)
}
@section Description{
<p>@Html.Raw(Resources.ListBox.Index_Text0)</p>
<p>@Html.Raw(Resources.ListBox.CaseSensitiveSearchDescription_Text0)</p>
<p>@Html.Raw(Resources.ListBox.Index_Text2)</p>
}
マニュアル