I have a grid combo box in my grid control that has an inventory list. I want the user to be able to search by typing text into the input box but I do not want them to be able to enter and save items that are not in the list. How would I do this?
I also need to be able to search on the value or the text. So in the screenshot below the user should be able to search on the number or the description in the string.
For example, right now I can type in 10154 and the item will be found but if I type in Armor nothing happens.
CODE:
@Html.EJS().Grid("ContainerGrid").DataSource(DataManager => { DataManager.Json(@Model.ContainerTransactions.ToArray()).InsertUrl("/Container/AddContainerTransaction").UpdateUrl("/Container/UpdateContainerTransaction").RemoveUrl("/Container/DeleteContainer").Adaptor("RemoteSaveAdaptor"); }).Width("auto").Columns(col =>
{
col.Field("TransactionNo").Visible(false).Add();
col.Field("InventoryID").HeaderText("Item").IsPrimaryKey(true).Width("40").Visible(false).EditType("dropdownedit").Edit(new { create = "create", read = "read", destroy = "destroy", write = "write" }).ValidationRules(new { required = true }).Add();
...
}).ActionBegin("actionBegin").ActionComplete("actionComplete")
<script>
var elem;
var inventoryObj;
var inventoryData = @Html.Raw(Json.Encode(@Model.Inventory.ToArray()));
function create(args) {
elem = document.createElement('input');
return elem;
}
function destroy() {
inventoryObj.destroy();
}
function read(args) {
return inventoryObj.value;
}
function write(args) {
inventoryObj = new ej.dropdowns.ComboBox({
dataSource: inventoryData,
placeholder: args.column.headerText,
value: args.rowData[args.column.field],
floatLabelType: "Always",
fields: { text: "CatalogDescription", value: "InventoryID" },
change: function() {
description = inventoryObj.text;
}
});
inventoryObj.appendTo(args.element);
}
</script>
@Html.EJS().Grid("Grid").DataSource(dataManager =>
{
dataManager.Json(ViewBag.DataSource1.ToArray()).InsertUrl("/Home/Insert").RemoveUrl("/Home/Remove").UpdateUrl("/Home/Update").Adaptor("RemoteSaveAdaptor");
}).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right). Add();
col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add();
col.Field("ShipCountry").HeaderText("Ship Country").ValidationRules(new { required = "true" }).Edit(new { create = "create", read = "read", destroy = "destroy", write = "write" }).Width("150").Add();
}).AllowPaging().EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>
() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
<script>
var elem;
var inventoryObj;
var inventoryData = @Html.Raw(Json.Encode(ViewBag.DataSource1));
function create(args) {
elem = document.createElement('input');
return elem;
}
function destroy() {
// destroy the component
inventoryObj.destroy();
}
function read(args) {
// return the dropdown value to the Grid
return inventoryObj.value;
}
function write(args) {
// create the Dropdown component to edit a column
inventoryObj = new ej.dropdowns.DropDownList({
dataSource: inventoryData,
placeholder: args.column.headerText,
value: args.rowData[args.column.field],
floatLabelType: "Always",
fields: { text: "ShipCountry", value: "ShipCountry" },
// enable the filtering feature
allowFiltering: true,
});
inventoryObj.appendTo(args.element);
}
</script>
|
function write(args) {
inventoryObj = new ej.dropdowns.DropDownList({
-----
// shown multiple items in the dropdown popup
itemTemplate: "<span><span class='OrderID'>${OrderID}</span><span class ='ShipCountry'> - ${ShipCountry}</span></span>",
//bind the filtering event handler
filtering: (e) => {
// perform Searching on ShipCountry and OrderID column
if (e.text == '') {
e.updateData(inventoryData); // load overall data when search key empty.
}
else {
var dropdown_query = new ej.data.Query();
// frame the filter query for multiple columns.
dropdown_query.where(new ej.data.Predicate('ShipCountry', 'contains', e.text, true).or('OrderID', 'contains', e.text, true));
e.updateData(inventoryData, dropdown_query); // execute the customized query
}
}
});
-----
}
|
worked perfectly. Thanks