Issue filling dropwdown data adding row in a grid

Good morning,
I created an ejs-grid.
<ejs-grid id="Grid" locale="it-IT" width="100%"  allowPdfExport="true" allowPaging="true" allowSorting="true" allowFiltering="true" allowSelection="true" cellEdit="OnCellEditing" toolbar=toolbarItems toolbarClick="ToolClick">
.
.
<e-grid-editSettings allowAdding="true" mode="Dialog" allowEditing="true" allowDeleting="true" showDeleteConfirmDialog="true" showConfirmDialog="true"></e-grid-editSettings>
.
.

To fill the grid i'm using a datamanager:

<e-data-manager url="@Url.Action("UrlDatasourcePlatesDrivers", "UirnetMission")" removeUrl="/UirnetMission/DoPlatesDriversCrudOperation" updateUrl="/UirnetMission/DoPlatesDriversCrudOperation" crudUrl="/UirnetMission/DoPlatesDriversCrudOperation" adaptor="UrlAdaptor"></e-data-manager>  

I need to create new rows, and i want to use dropdown filled with a set of data for some field.

<e-grid-column field="Cognome" allowEditing="true" headerText="Autista" editType="dropdownedit" edit="new {@params = @DropDownListAutisti }"  textAlign="Center" width="100"></e-grid-column>

var DropDownListAutisti = new Syncfusion.EJ2.DropDowns.DropDownList() { DataSource = ViewBag.AllDriversSurname, Query = "new ej.data.Query()", Placeholder = "Cognome" };

The problem is that i can see only the set of data present in the grid, not all the data of the ViewBag.
For example: if i have in the grid three rows with three surnames , i can choose only these three in the dropdown when i want to create a new row, not all the surnames loaded in the Viewbag.AllDriversSurname

The code in the controller:
  public async Task<JsonResult> UrlDatasourcePlatesDrivers([FromBody] DataManagerRequest dm,string action)
        {
            GetDriversAndPlates(DateTime.Now.AddDays(-7), DateTime.Now.AddDays(7)).Wait();

            List<string> turni = new List<string>() { "Turno Notte 1-7", "Turno Scanner 8-13", "Turno Vm 13-19" };

            ViewBag.Turni = turni;

            HttpClient clientPlates = new HttpClient();
            HttpClient clientDrivers = new HttpClient();
            var platesRes = await clientPlates.GetAsync("https://xxxxxxx/GetTruckPlates");
            var driversRes = await clientDrivers.GetAsync("https://xxxxxxxxx/GetDrivers");

            var contPlates = await platesRes.Content.ReadAsStringAsync();
            var contDrivers = await driversRes.Content.ReadAsStringAsync();

            List<Truck> trucks = JsonConvert.DeserializeObject<List<Truck>>(contPlates);
            List<Driver> drivers = JsonConvert.DeserializeObject<List<Driver>>(contDrivers);

            ViewBag.AllDrivers = drivers.Select(x => x.CodiceFiscale).ToList();
            ViewBag.AllDriversSurname = drivers.Select(x => x.Cognome).ToList();
            ViewBag.AllPlates = trucks.Select(x => x.Targa).ToList(); ;
            ViewBag.AziendeTruck = new List<string>() { "xxxxx","yyyyy" };
            List<AssociationDriverPlateViewModel> viewModels = new List<AssociationDriverPlateViewModel>();

            foreach (var plateDrive in driversAndPlatesList)
            {
                viewModels.Add(new AssociationDriverPlateViewModel(plateDrive));
            }

            ViewBag.DataSourcePlateDrive = viewModels;

            IEnumerable DataSource = ViewBag.DataSourcePlateDrive;
            DataOperations operation = new DataOperations();
            if (dm.Search != null && dm.Search.Count > 0)
            {
                DataSource = operation.PerformSearching(DataSource, dm.Search);  //Search
            }
            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
            {
                DataSource = operation.PerformSorting(DataSource, dm.Sorted);
            }
            if (dm.Where != null && dm.Where.Count > 0) //Filtering
            {
                DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
            }
            int count = DataSource.Cast<AssociationDriverPlateViewModel>().Count(); //dataVisitList.Count;
            if (dm.Skip != 0)
            {
                DataSource = operation.PerformSkip(DataSource, dm.Skip);         //Paging
            }
            if (dm.Take != 0)
            {
                DataSource = operation.PerformTake(DataSource, dm.Take);
            }
            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
        }


I appreciate any kind of help.
Thank you.
Greetings




1 Reply 1 reply marked as answer

AG Ajith Govarthan Syncfusion Team September 11, 2020 02:10 PM UTC

Hi Giacomo, 

Thanks for contacting Syncfusion support. 

Based on the attached code example we have prepared sample but we did not face the mentioned behavior in our sample. In the prepared sample we have added custom dataSource , query and placeholder parameter for dropdown component using the edit params feature. 

For your convenience we have attached the sample so please refer the sample for your reference. 

Code Example: 
Index.cshtml 
 
    @{ 
 
        var DropDownListAutisti = new Syncfusion.EJ2.DropDowns.DropDownList() { DataSource = ViewBag.DrpData, Query = "new ej.data.Query()", Placeholder = "Cognome" }; 
    } 
 
@Html.AntiForgeryToken() 
<ejs-grid id="Grid" allowPaging="true"  toolbar="@(new List<string>() {"Add", "Edit", "Update", "Delete" })" locale="it"> 
    <e-data-manager url="/Home/UrlDataSource" adaptor="UrlAdaptor" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Remove"></e-data-manager> 
 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" showDeleteConfirmDialog="true" showConfirmDialog="true"></e-grid-editSettings> 
 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column> 
        <e-grid-column field="CustomerID" headerText="Customer ID" type="string" validationRules="@(new { required= true })" width="120"></e-grid-column> 
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" editType="numericedit" width="120"></e-grid-column> 
        <e-grid-column field="ShipCity" headerText="Ship City" editType="dropdownedit" edit="new {@params = DropDownListAutisti }"   width="150"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
<script> 
 
    document.addEventListener('DOMContentLoaded', function () { 
    ej.base.setCulture('it'); 
        ej.base.setCurrencyCode('EUR'); 
        var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0]; 
      
 
    ej.base.L10n.load({ 
        'it': { 
            'grid': { 
                'EmptyRecord': 'Keine Aufzeichnungen angezeigt', 
                'GroupDropArea': 'Ziehen Sie einen Spaltenkopf hier, um die Gruppe ihre Spalte', 
                'UnGroup': 'Klicken Sie hier, um die Gruppierung aufheben', 
                'EmptyDataSourceError': 'DataSource darf bei der Erstauslastung nicht leer sein, da Spalten aus der dataSource im AutoGenerate Spaltenraster', 
                'Item': 'Artikel', 
                'Items': 'Artikel' 
            }, 
            'pager': { 
                'currentPageInfo': '{0} von {1} Seiten', 
                'totalItemsInfo': '({0} Beiträge)', 
                'firstPageTooltip': 'Zur ersten Seite', 
                'lastPageTooltip': 'Zur letzten Seite', 
                'nextPageTooltip': 'Zur nächsten Seite', 
                'previousPageTooltip': 'Zurück zur letzten Seit', 
                'nextPagerTooltip': 'Zum nächsten Pager', 
                'previousPagerTooltip': 'Zum vorherigen Pager' 
            } 
        } 
    }); 
 
        }); 
</script> 




If you still face the issue then please share the below details to find the root cause of the issue. 

  1. Please try to reproduce the issue in the attached sample.

  1. Share the screenshot the issue.
 
  1. Share the Syncfusion package version.

Regards, 
Ajith G. 


Marked as answer
Loader.
Up arrow icon