<ej-grid id="FlatGrid" allow-paging="true" datasource="ViewBag.dataSource">
<e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true"></e-edit-settings>
<e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"add","edit","update","cancel"}' />
<e-columns>
<e-column field="OrderID" is-primary-key="true" header-text="Order ID"></e-column>
<e-column field="CustomerID" header-text="CustomerID">
<e-edit-template create="create" read="read" write="write">
</e-edit-template>
</e-column>
<e-column field="Freight" header-text="Freight"></e-column>
<e-column field="ShipCity" header-text="ShipCity">
</e-column>
</e-columns>
</ej-grid>
<script type="text/javascript">
function create() {
return $("<input>");
}
function write(args) {
obj = $('#FlatGrid').ejGrid('instance');
var data = ej.DataManager(obj.model.dataSource);
args.element.ejAutocomplete({ width: "100%", dataSource: data, fields: { text: "CustomerID" }, enableDistinct: true, value: args.rowdata !== undefined ? args.rowdata["CustomerID"] : "", select: "onautoselect" });
}
function read(args) {
args.ejAutocomplete('suggestionList').css('display', 'none');
return args.ejAutocomplete("getValue");
}
$("#FlatGrid").keyup(function (e) {
if (e.keyCode == 40 && $(e.target).hasClass("e-autocomplete")) {
var autocomp = $("#FlatGridCustomerID").ejAutocomplete("instance")
if (autocomp.getValue() != "" && autocomp.getActiveText() != "No suggestions")
$(e.target).val(autocomp.getActiveText());
}
});
</script> |
I tried to bind to my own data through Json API, when I type things in the autocomplete field, all the candidates show up in the drop down list regardless of what I am typing.
Is there anything wrong with my code?
And also, is there a simple way to bind ViewBag datasource to the autocomplete control in the Script section?
public ActionResult DataSource([FromBody] Syncfusion.JavaScript.DataManager dm)
{
if (dm.Where[0].value.ToString() == "")
{
return null;
}
else
{
IEnumerable Data = order;
var result = order.ToList();
var search = from n in result where n.CustomerID.ToLower().Contains(dm.Where[0].value.ToString()) select n; // Filtering based on the searched word
return Json(search.ToList());
}
} |
function write(args) {
obj = $('#FlatGrid').ejGrid('instance');
var data = @Html.Raw(Json.Serialize(ViewBag.dataSource));
args.element.ejAutocomplete({ width: "100%", dataSource: data, fields: { text: "FirstName" }, enableDistinct: false, value: args.rowdata !== undefined ? args.rowdata["CustomerID"] : "", select: "onautoselect" });
} |