- Home
- Forum
- ASP.NET MVC
- Grid Autocomplete Cell
Grid Autocomplete Cell
- DialogEditing or
- Inline Form Editing or
- External Form Editing
Thanks for using Syncfusion products.
We have provided support for “EditTemplate” which is used to create custom editor (like AutoComplete). Using “EditTemplate” we can render the AutoComplete control as follows,
| @(Html.EJ().Grid<object>("FlatGrid") .Columns(col => })) <script type="text/javascript"> function create() { return $("<input>"); }
function write(args) { obj = $('#FlatGrid').ejGrid('instance'); var data = []; $.ajax({ //get the data for the autoComplete control type: "GET", url: "/Grid/BatchDataSource", success: function (data, status, xhr) { var data1 = ej.DataManager(data.result).executeLocal(new ej.Query().select("CustomerID")); args.element.ejAutocomplete({ width: "100%", dataSource: data1, enableDistinct: true, value: args.rowdata !== undefined ? args.rowdata["CustomerID"] : "" }); } }); }
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 = $("#EdittemplateEmployeeID").ejAutocomplete("instance") if (autocomp._getActiveText() != "No suggestions") $(e.target).val(autocomp._getActiveText()); } }); </script> |
Refer to the below link for more clarification about EditTemplate,
https://help.syncfusion.com/aspnetmvc/grid/editing#cell-edit-template
https://mvc.syncfusion.com/demos/web/grid/edittemplate
Regards,
Gowthami V.
- The CustomerID is stored in the Order table and used to display as well, however I am hoping to store CustomerID (e.g. Int or GUID) in the Order table but display CustomerName on the grid (and also use the name to search for the customer).
- Customer table will store the CustomerName field
- I believe the sample solution retrieves data and just provides the autocomplete functionality for entire data in tabel. Issue for me is that BatchDataSource call will retrieve subset of primary data using primary ID. But we want to be able to connect any individual record within the subset data on the grid to secondary (related) data using autocomplete.
Primary Data
|
CourseRegistration |
|
StudentID |
|
CourseID |
Secondary Data (Related Data)
|
Course |
|
CourseID |
|
CourseName |
Query : The CustomerID is stored in the Order table and used to display as well, however I am hoping to store CustomerID (e.g. Int or GUID) in the Order table but display CustomerName on the grid (and also use the name to search for the customer). Customer table will store the CustomerName field
Your requirement can be achieved using ForeignKeyField and ForeignKeyValue of the columns. ForiegnKey column requires a dataSource (related dataSource), can be bound by the ForeignKeyField and ForeignKeyValue values. It will display the ForeignKeyValue of dataSource(bound to the column) in the Grid.
Also you would like to render the autoComplete instead of dropdown. We suggest you to use the filterSearch along with dropdownlist which is similar to the autocomplete. Refer to the following code example.
| @(Html.EJ().Grid<object>("Editing") .Datasource(ds => ds.URL("/Home/BatchDataSource").BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.UrlAdaptor)) .AllowPaging() .ClientSideEvents(eve => eve.CellEdit("cellEdit").CellSave("cellSave")) .Columns(col => { col.Field("OrderID").IsPrimaryKey(true).Add(); col.Field("EmployeeID").ForeignKeyField("EmployeeID").ForeignKeyValue("FirstName").DataSource(ViewBag.datasource).Add(); . . . . . }) ) <script> function cellEdit(args) { if (args.columnName == "EmployeeID") { args.columnObject.dataSource = undefined; args.columnObject.editParams = { enableFilterSearch: true }; } } function cellSave(args){ this.model.columns[1].dataSource = @Html.Raw(Json.Encode(ViewBag.datasource));//EmployeeID column } |
We have prepared a sample that can be downloaded from the following location.
https://www.syncfusion.com/downloads/support/forum/121775/ze/BatchEdit_dropdownAutoComplete276765115
Regards,
Seeni Sakthi Kumar S.
We are happy to hear that the solution meets your requirement. Please let us know if you need any further assistance.
Regards,
Seeni Sakthi Kumar S.
thanks
From your query, we understood that you would like to render the ejAutoComplete for the foreignKey column using the ej.ForeignKeyAdaptor. It is possible but the foreignKeyAdaptor will work only with the local datasource. Refer to the below sample,
Sample: https://www.syncfusion.com/downloads/support/forum/121775/ze/ForeignKey_AutoComplete1788849815
| @(Html.EJ().Grid<object>("Editing") .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource).InsertURL("/Home/Insert").UpdateURL("/Home/Update").RemoveURL("/Home/Delete").Adaptor(AdaptorType.RemoteSaveAdaptor)) .AllowPaging() . .. . . . . .Columns(col => { col.Field("OrderID").HeaderText("Order ID").Add(); . . . . . col.Field("FirstName").EditTemplate(temp => { temp.Create("create").Read("read").Write("write"); }).Add();//Virtual column }) .ClientSideEvents(evt => evt.Load("onLoad")) ) <script> var data = @Html.Raw(Json.Encode(ViewBag.datasource1)); var arr =[{ dataSource: data, foreignKeyField: "EmployeeID", foreignKeyValue: "FirstName" }];
function onLoad(args) { this.model.dataSource.adaptor = new ej.ForeignKeyAdaptor(arr,"remoteSaveAdaptor"); } function create() { return "<input>"; } function read(args) { args.ejAutocomplete('suggestionList').css('display', 'none'); return args.ejAutocomplete("getValue"); } function write(args) { var data1 = ej.DataManager(data).executeLocal(new ej.Query().select("FirstName")); args.element.ejAutocomplete({ width: "100%", dataSource: data1, enableDistinct: true, value: args.rowdata !== undefined ? args.rowdata["FirstName"] : "" }); } $("#Editing").keyup(function (e) { if (e.keyCode == 40 && $(e.target).hasClass("e-autocomplete")) { var autocomp = $("#EditingFirstName").ejAutocomplete("instance") if (autocomp._getActiveText() != "No suggestions") $(e.target).val(autocomp._getActiveText()); } }); |
The above code example illustrates how to render the foreignkey column using the ej.ForeignKeyAdaptor. ForeignKeyAdaptor accepts two parameters. First parameter accepts the array of objects, which has dataSource, foreignKeyField and foreignKeyValue for the virtual column (“FirstName”) in Grid. Whereas the second parameter holds the type of secondary adaptor (either JsonAdaptor or remoteSaveAdaptor).
ejAutoComplete rendered using the editTemplate of ejGrid.
Please make a note that ForeignKey column of the Grid (at the column level) will not accept editType other than dropDown.
| .Columns(col => { col.Field("EmployeeID").HeaderText("FirstName").ForeignKeyField("EmployeeID").ForeignKeyValue("FirstName").Add(); . . .. . }) |
So we did it using the ej.ForeignKeyAdaptor and at the same time foreignKeyAdaptor handles only with local datasource.
In your query, you have quoted the “adaptor” and doesn’t mention any adaptor name. So we have done this using foreignKeyAdaptor. If we misunderstood your query, please explain your requirement specifically.
Regards,
Seeni Sakthi Kumar S.
If I click on it individual item then the cell is just empty
Issue Three (check box interaction)
For some reason check box is not working correctly when editing if I try to click on check box while hovering over the check box then I get to see the stop icon
In this case if I click anywhere else within the cell then Check box is updated, but the issue is unpredictable as it doesn’t happen 100% of the time.
Issue Four
Based on check box value on the grid column is it possible to
disable the row so that the row is locked and users aren’t allowed to delete
and individual columns aren’t editable as well.
I have server side validation but client side validation would be nice
(also showing dialog to inform that the records can’t be deleted)
If you could provide some assistance that would be greatly appreciated.
Regards
Prasanth
Attachment: GridIssues_326c3d05.zip
| @(Html.EJ().Grid<object>("Editing") .Datasource(ds => ds.URL("/Home/BatchDataSource").BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.UrlAdaptor)) .AllowPaging() .ClientSideEvents(eve => eve.CellEdit("cellEdit")) . . . .Columns(col => { . . . col.Field("Verified").HeaderText("Verified").EditType(EditingType.Boolean).Width(80).Add(); }) ) <script> function cellEdit(args) { if(!args.rowData.Verified) args.cancel = true . . .. } </script> |
- Once searched - filter, need to double click on the filtered list entry to select (couldn't achieve this with single click on or enter key)
- White space is still there
- Checkbox issue I haven't tested but assume it's there as I think the issues might be due to script files not being added correctly or has incorrect content
Attachment: ProjectXEDWeb_ee063357.zip
Hi Prasanthan,
Thanks for using Syncfusion products.
We have provided support for “EditTemplate” which is used to create custom editor (like AutoComplete). Using “EditTemplate” we can render the AutoComplete control as follows,
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds => ds.URL("BatchDataSource").BatchURL("BatchUpdate").Adaptor(AdaptorType.UrlAdaptor))
. . . .
. . . .
.Columns(col =>
{
. . . .
col.Field("CustomerID").HeaderText("Customer ID").EditTemplate(a => { a.Create("create").Read("read").Write("write"); }).TextAlign(TextAlign.Right).Width(90).Add();
}))
<script type="text/javascript">
function create() {
return $("");
}
function write(args) {
obj = $('#FlatGrid').ejGrid('instance');
var data = [];
$.ajax({
//get the data for the autoComplete control
type: "GET",
url: "/Grid/BatchDataSource",
success: function (data, status, xhr) {
var data1 = ej.DataManager(data.result).executeLocal(new ej.Query().select("CustomerID"));
args.element.ejAutocomplete({ width: "100%", dataSource: data1, enableDistinct: true, value: args.rowdata !== undefined ? args.rowdata["CustomerID"] : "" });
}
});
}
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 = $("#EdittemplateEmployeeID").ejAutocomplete("instance")
if (autocomp._getActiveText() != "No suggestions")
$(e.target).val(autocomp._getActiveText());
}
});
script>
Refer to the below link for more clarification about EditTemplate,
http://help.syncfusion.com/aspnetmvc/grid/editing#cell-edit-template
http://mvc.syncfusion.com/demos/web/grid/edittemplate
Regards,
Gowthami V.
Hi,
$("#autocomplete").ejAutocomplete({
popupWidth: '152px'
});Attachment: autocomplete_grid_a1d9f959.7z- 15 Replies
- 6 Participants
-
PR Prasanth
- Jan 25, 2016 01:26 PM UTC
- Jan 29, 2018 11:56 AM UTC