Hi,
I can both insert and update a record in grids into the server but can not delete any record. I have read documentations and watch videos on how to perform CRUD using the Observables but l still can not delete record from the server. kindly assist.
1. Package 19.5.4
2. Each time l try to delete a row it would complains of this error http://localhost:5000/api/Department/undefined
Bad request 404.
3. The moment l hit the delete button it would hang and it would allow any further action unless l refresh the page.
deleteRecord(state: any): Observable<any> {
const id = state.data[0].DepartmentID;
const url = `${this.APIUrl}/${id}`;
return this.http.delete<any>(url, httpOptions);
}
|
protected getData(state: DataStateChangeEventArgs): Observable<DataStateChangeEventArgs> {
. . .
return this.http
.get(
`${this.BASE_URL}?${pageQuery}${sortQuery}&$inlinecount=allpages&$format=json`)
.pipe(map((response: any) => response))
.pipe( map(
(response: any) =>
<DataResult>{
result: response['d']['results'],
count: parseInt(response['d']['__count'], 10),
}
)
)
.pipe((data: any) => data);
}
|
Hi Pavithra,
Thank you for the solutions you provided as my delete method is now working fine.
I'm having problem with paging in grid. I did change my code to as to try the example that l found in your documentation but at the moment my grid is no longer populating data from the server. I want my grid to perform paging like in the sample (see link below). Kindly assist
https://stackblitz.com/edit/angular-kqu7vy-qg3vwz?file=app.component.ts
I got this script error: response.json is not a function
Hi Pavithra
I have done exactly what you have asked me to do, but still my grid is no longer population data from the server let alone paging as l keep getting this error:
ERROR TypeError: Cannot read properties of undefined (reading 'results')
at MapSubscriber.project (main.js:57:34)
at MapSubscriber._next (vendor.js:222861:35)
at MapSubscriber.next (vendor.js:85097:18)
at MapSubscriber._next (vendor.js:222867:26)
at MapSubscriber.next (vendor.js:85097:18)
at FilterSubscriber._next (vendor.js:245638:30)
at FilterSubscriber.next (vendor.js:85097:18)
And so on.
Hi Pavithra,
From the provided demo example l was able to create sidebar plus tree view project and now I am trying to create router links for each sidebar menu button but it's not working. Kindly assist
Hi Indhumathy,
Thank you for your suggestions. I ave discovered where l made the mistake in my codes. I have fixed the problem
Regards
Hi Indhumathy,
Iwant to create a syncfusion grid modal form like the above picture. I can insert data into the server via web API, but l have no idea how to insert picture as i have search for several hours about this but was not able to find any useful materials. For instance, I have EmployeeId, EmployeeName, PhotoOfEmployee,
How to insert Picture of each employee into the server using observables method and how to populate grid that would contains photo etc? I'm using syncfusion angular. Kindly assist
Hello,
I can load the grid from the server but pagination is not working as it keeps signally waiting. Kindly assist me to fix paging issue on my grid
Hi Charles,
We have tried to reproduce the issue at our end, but it is working fine with the provided code. Please refer to the below sample link for more information.
https://stackblitz.com/edit/angular-n6yvrn?file=main.ts
So could you please share the below details that will be helpful for us to provide a better solution as early as possible?
Regards,
Pavithra S
Hi Pavithra,
In the link that you provided the paging is not working. That is, when you click page 2 or next it would change but the grid contents remain the same. It's expected that when one click page 2 then more data from the server would be show on the grid.
Answers to your questions above:
TypeError: Cannot read properties of undefined (reading 'results')
3. I've tried what is found on the link and the errors in answer number 1 was what l got.
What l really want is that the grid should populate all records from the server to the browser. For example Customers table is created in the database which contains 200 records of customers. So l want to load all the 200 records of customer to the browser (grid) via the server. Then the grid should only show 10 records of customer per page on the browser. If page 1 shows 1-10 customer record, then when l click page 2 it should show 11-20 customers record etc
Hi Charles,
Since you’re using the “Custom Binding” in Grid components Grid
will send the current page details to the “dataStateChange” event. Inside this
event, you need to call your service and return the required data for that Grid
page. But in your code, you are returning all the data for all calls.
That’s why it looks like the pagination is not
working. If you want to load all the data at initial rendering and do
pagination without sending further requests to the server, then it will act as
local data binding and all the Grid data actions and CRUD actions will be done
locally.
Could you please confirm whether you want to do only the pagination or all the Grid actions (page, filter, sort, CRUD, etc.) locally without accessing the server again? Based on this we will provide a solution as early as possible.
Regards,
Pavithra S
Hi Pavithra,
I have solved the problem. Thank you.
I'm having issue with passing selected grid row to textboxes in another component.
In your documentations there is dialog popup property that is bind to a grid for adding and editing data, but l don't want to make use of that. I have created an external form called Employee Form in a component and Employee List (grid) in another component. So when i select a row in grid and click on my custom 'Edit the Employee' button then the external form textboxes should be filled with that grid row contents. This is to enable me to proceed with other forms that would depend on the Employee form. Kindly assist
Employee Form component
Hi Charles,
You can get the currently selected Grid record details by using the “getSelectedRecords” method. So, while clicking the Edit button, you can pass these details using the decorators like “@Input” and “@Output” if the two components are parent and child. Otherwise, you can use the angular Service to pass the data between the components. Please refer to the below API and reference links for more information.
API : https://ej2.syncfusion.com/angular/documentation/api/grid/#getselectedrecords
Reference : https://www.c-sharpcorner.com/blogs/pass-data-between-component-to-another-component-in-angular
Also, we have inbuilt support for adding a template in the default edit dialog. So, you can add the customized editor components in the Dialog without defining a separate component. Please refer to the below demo and documentation link for more information.
Demo : https://ej2.syncfusion.com/angular/documentation/grid/editing/template-editing/#reactive-forms
https://ej2.syncfusion.com/angular/demos/#/material/grid/dialog-reactive-form
Please get back to us if you need further assistance on this.
Regards,
Pavithra S
Hi Pavithra,
Thank you. I have not be able to see a good example on how to use
“getSelectedRecords”. I have tried the @Input and @output decorator but was not successful using Syncfusion angular input controls.
I have also tried using the Angular Service but I'm having issues passing data from grid to input control on form, The codes below are what I've tried. Kindly assist.
Hi Charles,
You can achieve your requirement by using our Reactive forms Dialog template editing feature which helps to create the FormGroup with FormControls for each columns while editing. Please refer to the below demo and documentation link for more information as we suggested.
Demo : https://ej2.syncfusion.com/angular/documentation/grid/editing/template-editing/#reactive-forms
https://ej2.syncfusion.com/angular/demos/#/material/grid/dialog-reactive-form
If this doesn’t meet your requirement, please share the below details that will be helpful for us to provide a better solution as early as possible?
Regards,
Pavithra S
Hi Pavithra
I have resort to use the Hierarchy grid. The parent grid is loading but the child grid is not populating data from the server. I'm using observable method. below is my codes. Kindly assist
I intend to add more child grid such as Academic, Work experience, Next-of-kin etc. It is possible using the hierarchy grid?
Hi Charles,
Query#1: I have resort to use the Hierarchy grid. The parent grid is loading but the child grid is not populating data from the server. I'm using observable method. below is my codes. Kindly assist
Due to some complexities, we could not set the observable binding to the child grid. However, you can fetch all the data using the service at initial rendering and set it to the child Grid. So the child Grid will perform the data actions locally. Please refer to the below code example and sample link for more information.
export class AppComponent { . . .
public ngOnInit(): void {
this.service2.getData().subscribe((x) => { this.grid.childGrid = { dataSource: x.result, queryString: 'EmployeeID', allowPaging: true, pageSettings: { pageSize: 6, pageCount: 5 }, columns: [ { field: 'EmployeeID', headerText: 'Employee ID', textAlign: 'Right', width: 120, }, { field: 'FirstName', headerText: 'First Name', width: 120 }, { field: 'LastName', headerText: 'Last Name', width: 120 }, ], }; this.grid.refreshHeader(); }); } }
|
Query#2: I intend to add more child grid such as Academic, Work experience, Next-of-kin etc. It is possible using the hierarchy grid?
If you want to add multilevel child grids, then you can set the childGrid property in a hierarchy manner. Please refer to the below demo which has 2 levels of the child.
https://ej2.syncfusion.com/angular/demos/#/material/grid/hierarchy
Or if you want to shoe multiple grids in the same level, then you can use the detail sample feature where you can render multiple Grids while expanding the parent row. Please refer to the below documentation and sample link for more information.
https://ej2.syncfusion.com/angular/documentation/grid/row/detail-template/
https://ej2.syncfusion.com/angular/demos/#/material/grid/detail-template
Regards,
Pavithra S
Hi Pavithra,
In response to the solutions that you have provided, I want to create four child grid and not a multilevel one. Just one parent grid and for child grid.
I have tired other examples found on hierarchy grid documentations but was not successful. l wonder why It is only local binding of the hierarchy grid that seems to work. So l have also tried using the Data Manager to bind the hierarchy grid system but the child grid is still not loading data from the server. It shows only the column header text but no data from the server. Below is my codes;
Hi Charles,
Query#1: I want to create four child grid and not a multilevel one. Just one parent grid and for child grid.
We suggest the Detail template feature to achieve your requirement which provides an option to render custom components for each parent row. Please refer to the below code example and documentation link for more information.
<div class="control-section"> <ejs-grid #grid [dataSource]='data' id='Grid'> <ng-template #detailTemplate let-data> <div style="display:inline-block"> <ejs-grid id='ChildGrid1' [dataSource]='childData1' [allowPaging]="true" width="49%"> <e-columns> . . . </e-column> </e-columns> </ejs-grid> <ejs-grid id='ChildGrid2' [dataSource]='childData2' [allowPaging]="true" width="49%"> <e-columns> . . . </e-columns> </ejs-grid> </div> </ng-template> <e-columns> <e-column field='EmployeeID' headerText='Employee ID' width='125' textAlign='Right'></e-column> . . . </e-columns>
</ejs-grid> </div>
|
Documentation: https://ej2.syncfusion.com/angular/documentation/grid/row/detail-template/
Query#2: l have also tried using the Data Manager to bind the hierarchy grid system but the child grid is still not loading data from the server.
It shows only the column
header text but no data from the server
The child Grid data is binding fine with DataManager at our end. So if you want to still use the Hierarchy Grid instead of Details template to achieve your requirement please share an issue reproducible sample that will be helpful for us to provide a better solution.
Regards,
Pavithra S
Hi Pavithra,
The codes you have provided does not meet my requirement. I think the Hierarchy grid is what l want to use. My parent grid is Employee grid and the child is next-of-kin (nok) grid. So l want to bind the parent and child grid with a unique EmployeeID. When l select an employee then it should display the next-of-kin record in child grid for that particular Employee.
Parent grid- Employee ID: 001 EmployeeName: David Oher Department: Account and records
child grid- Employee ID: 001 FirstName: Linda OtherName: Oher Relationship: Sister
The link below is what l have tried
https://stackblitz.com/edit/angular-kqu7vy-rwnq62?file=app.component.ts,app.component.html
Hi Charles,
In your sample, we could see that you want to set the Grid with local data binding. So, we suggest you set the “offline” property as true and set an appropriate Adaptor. In your case it seems that you are using an API endpoint, so we suggest our WebApiAdaptor. Please refer to the below code example and sample link for more information.
this.data = new DataManager({ url: 'https://services.odata.org/V4/Northwind/Northwind.svc/Employees/', adaptor: new ODataV4Adaptor(), offline: true, }, new Query().take(6));
this.childGrid = { dataSource: new DataManager( { url: 'https://services.odata.org/V4/Northwind/Northwind.svc/Orders/', adaptor: new ODataV4Adaptor(), offline: true, }, new Query().take(6) ), queryString: 'EmployeeID', columns: [ { field: 'EmployeeID', headerText: 'ID', width: 50 }, { field: 'CustomerID', headerText: 'FirstName', width: 80 }, ], };
|
Sample: https://stackblitz.com/edit/angular-kqu7vy-wyokne?file=app.component.ts,app.component.html
Regards,
Pavithra S
Hi Pavithra
Your solution have work, thank you.
I tried to add a second and third child but it didn't work. I want it like in the below structure if possible
ParentGrid(Employee list)
childGrid1(next-of-kin), childGrid2(Academic), childGrid3(Work experience).
Thank you
Hi Charles,
By default, using the Hierarchy Binding feature we could not render multiple child Grid at the same level. So, we are afraid that your requirement is not feasible with the current architecture.
Please get back to us if you need further assistance.
Regards,
Pavithra S
Hi Pavithrw,
Thank you for the clarification of hierarchy grid. What about the master/detail relationship grid? Does it renders multiple detail grid at the same level?
You also provided the option of parent grid and multiple child grid. How would l link EmployeeID in the parent grid to the multiple child/detail grid in the codes below?
<div class="control-section">
<ejs-grid #grid [dataSource]='data' id='Grid'>
<ng-template #detailTemplate let-data>
<div style="display:inline-block">
<ejs-grid id='ChildGrid1' [dataSource]='childData1' [allowPaging]="true" width="49%">
<e-columns>
. . .
</e-column>
</e-columns>
</ejs-grid>
<ejs-grid id='ChildGrid2' [dataSource]='childData2' [allowPaging]="true" width="49%">
<e-columns>
. . .
</e-columns>
</ejs-grid>
</div>
</ng-template>
<e-columns>
<e-column field='EmployeeID' headerText='Employee ID' width='125' textAlign='Right'></e-column>
. . .
</e-columns>
</ejs-grid>
</div>
Hi Charles,
You can achieve your requirement with the Detail Template feature by passing the corresponding parent key to the child Grid filter query. Please refer to the below code example and sample link for more information.
@Component({ selector: 'app-root', templateUrl: `<ejs-grid #grid [dataSource]="data" id="Grid"> <ng-template #detailTemplate let-data> <div style="display:inline-block"> <div style="float:left;width:49%;"> <h1>ChildGrid1</h1> <ejs-grid id="ChildGrid1" [dataSource]="childData1" [query]="getQuery(data.EmployeeID)" [columns]="columns1" [allowPaging]="true" [pageSettings]="pageSettings"> </ejs-grid> </div> <div style="float:right;width:49%;"> <h1>ChildGrid2</h1> <ejs-grid id="ChildGrid2" [dataSource]="childData2" [query]="getQuery(data.EmployeeID)" [columns]="columns2" [allowPaging]="true" [pageSettings]="pageSettings"> </ejs-grid> </div> </div> </ng-template> <e-columns> . . . </e-columns> </ejs-grid>`, }) export class AppComponent {
. . .
public getQuery(value: Date): Query { return new Query().where('EmployeeID', 'equal', value); } }
|
Sample: https://stackblitz.com/edit/angular-zrusab?file=app.component.html,app.component.ts,data.ts
Please get back to us if you need further assistance on this.
Regards,
Pavithra S
Hi Pavithra,
In this project all is working fine except that image is not uploaded to the destination folder. As soon as l click on the submit button l want image to be uploaded into a folder path. I don't know how to pass the upload action to submit button method. Kindly assist
https://stackblitz.com/edit/angular-kqu7vy-8xkfis?file=app.component.ts,emp.service.ts
Hi Pavithra,
My grid is not showing image from the destination folder. Kindly assist
https://stackblitz.com/edit/angular-nqk33p?file=order.service.ts
Hi Charles,
We tried to run the shared samples but got the below errors.
Sample: https://stackblitz.com/edit/angular-nqk33p?file=order.service.ts
|
Sample: https://stackblitz.com/edit/angular-kqu7vy-8xkfis?file=app.component.ts
|
So could you please share workable samples and share the screenshot of your issues for better understanding.
Regards,
Pavithra S
Hi Pavithra,
2. The second file shows the destination path folder where Employee Image are uploader to.
Kindly assist.
Hi Charles,
Thanks for your update.
From your code, it seems that you are trying to upload images through the EJ2 uploader inside a local folder and display it in the Grid. To validate this scenario please share the below details that will be helpful for us to provide a better solution.
Regards,
Pavithra S
Hi Pivithra,
Yes i'm loading image into a local folder which is working fine. My aim to assign the uploader code to the 'Submit' button so that as soon as l click on submit it would the save the image into the folder while the other data including the image name (text) will be save into the database via web API. This is working fine when I turn the auto upload to true, but it did upload selected image into it destination folder even when l have not click on submit. So i want all action to be done at once.
see link below:
https://stackblitz.com/edit/angular-nqk33p?file=main.ts
Second question is grid is not showing image from the folder even when there are many images in it. Below is my codes and link
https://stackblitz.com/edit/angular-kqu7vy-8xkfis?file=app.component.ts
Hi Charles,
Thanks for the details.
Query#1: My aim to assign the uploader code to the 'Submit' button so that as soon as l click on submit it would the save the image into the folder
From your query, we understood that you want to upload the files while clicking the submit button of the form. You can achieve your requirement by calling the “upload” method of the EJ2 uploader component inside the submit button click event which will upload the selected files (added to the upload queue).
https://ej2.syncfusion.com/angular/documentation/api/uploader#upload
Query#2: is grid is not showing image from the folder even when there are many images in it.
From the shared code and images, we suspect that the url given to the Grid column template must be not matched to the original folder in your sample. Could you please ensure whether the given url is correct (“http://localhost:5000/Photos{{ data.EmployeeID }}.png”) at your end? If yes, please share the script error and the path of any of your locally stored images for further validation.
Regards,
Pavithra S
Hi Pavithra,
Script Error:
GET http://localhost:5000/Photos/passportn.jpg 404 (Not Found)
Path of my stored image
C:\Users\don\Desktop\projectA\API core\WebApplication1\Photos\passportn.jpg
Just in case this didn't work, I will appreciate it if you can provide me with a working codes l can use to load my grid from my stored image folder.
Hi Charles,
Currently, we are preparing a working sample for displaying images in Grid from the local folder and we will share the sample on July 04th, 2022. Until then we appreciate your patience.
Regards,
Pavithra S
Hi Pavithra,
I'm yet to get the working sample for displaying images in Grid from the local folder as promised by you on 4th of July 2022.
RegardsC
Charles
Hi Charles,
Thanks for your patience.
We have prepared a sample in which we have displayed the images from the local folder using Grid column template. Please refer to the attached sample in which we have added a folder “Photos” inside the “wwwroot” and added the images which are shown inside the Grid column.
|
Regards,
Pavithra S
Hi Pavithra,
I was able to successfully replicate your sample by populating local data, but l could not accomplished it via data from the server as it displayed only the first row on the grid even as l have many records in the database. Kindly assist
https://stackblitz.com/edit/angular-nqk33p-5tyqds?file=app.component.ts,app.component.html
Hi Charles,
We have tried to reproduce the issue with the given code, but it is working fine at our end with the proper image URL. Please refer to the below screenshot for more information.
|
So could you please share an issue reproducible sample with a real API link instead of stack blitz or try to reproduce the issue in our previously shared sample and share it with us which will be helpful for us to validate further since it seems like an environmental issue only occurs in your sample.
Regards,
Pavithra S
Hi Pavithra,
From the sample you provided it loads the grid with its local data but l don't know how to connect to the database. I want to populate my grid with data from the database. Using the Northwind for example can you show me how to set datasource in Controller?
Regards
Hi Charles,
For binding data from the controller actions, you could use our EJ2 DataManager with an appropriate adaptor based on your server. Please refer to the below documentation for example code of remote data binding.
https://ej2.syncfusion.com/angular/documentation/grid/data-binding/remote-data/
If you are still facing the issue, please share the runnable sample with the issue as we requested earlier so that we could validate the issue and provide a better solution.
Regards,
Pavithra S
Hi Pavithra,
I didn't find anything related to my issue from the link documentation that you provided. I mentioned in my most recent post that the sample you provided shows how to load grid from local data. But my problem is how to create the controller to enable database interaction. A controller must be created to as grid at the frontend (angular) will populate data from the database. To load data from the database there must be a connection string for example SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-3HTYF;Initial Catalog=EmployeeDB;Integrated Security=True")
The codes below is from your sample project. Kindly assist me with connection to MSSQL database in it.
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Syncfusion.EJ2.Base;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace GridAngularCore.Controllers
{
public class HomeController : Controller
{
// GET: HomeController
public ActionResult Index()
{
return View();
}
// POST:
[HttpPost]
public IActionResult UrlDatasource([FromBody] DataManagerRequest dm)
{
IEnumerable DataSource = OrdersDetails.GetAllRecords();
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);
}
List<string> str = new List<string>();
if (dm.Aggregates != null)
{
for (var i = 0; i < dm.Aggregates.Count; i++)
str.Add(dm.Aggregates[i].Field);
}
IEnumerable aggregate = operation.PerformSelect(DataSource, str);
int count = DataSource.Cast<object>().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, aggregate = aggregate }) : Json(DataSource);
}
}
public class OrdersDetails
{
public static List<OrdersDetails> order = new List<OrdersDetails>();
public OrdersDetails()
{
}
public OrdersDetails(int OrderID, int EmployeeId, double Freight, DateTime OrderDate, string ShipCountry, string ShipID)
{
this.OrderID = OrderID;
this.EmployeeID = EmployeeId;
this.Freight = Freight;
this.OrderDate = OrderDate;
this.ShipCountry = ShipCountry;
this.ShipID = ShipID;
}
public static List<OrdersDetails> GetAllRecords()
{
if (order.Count() == 0)
{
int code = 1;
for (int i = 1; i < 2; i++)
{
order.Add(new OrdersDetails(code + 1, i + 0, 2.3 * i, new DateTime(1991, 05, 15, 2, 32, 5), "Denmark", "1"));
order.Add(new OrdersDetails(code + 2, i + 1, 3.3 * i, new DateTime(1990, 04, 04), "USA", "2"));
order.Add(new OrdersDetails(code + 3, i + 2, 4.3 * i, new DateTime(1957, 11, 30), "Brail", "3"));
order.Add(new OrdersDetails(code + 4, i + 3, 5.3 * i, new DateTime(1930, 10, 22), "Austria", "4"));
order.Add(new OrdersDetails(code + 5, i + 4, 6.3 * i, new DateTime(1953, 02, 18), "Switzerland", "5"));
code += 5;
}
}
return order;
}
public int? OrderID { get; set; }
public int? EmployeeID { get; set; }
public double? Freight { get; set; }
public DateTime? OrderDate { get; set; }
public string ShipCountry { get; set; }
public string ShipID { get; set; }
}
}
Hi Charles,
We have prepared a sample to connect the Northwind DB and fetch the data from the server using the “UrlAdaptor”. Please refer to the attached sample for more information.
Note: to bind the data source properly, kindly change the connectionstring of Northwnd.MDF file in the appsettings.json file.
Regards,
Pavithra S
Hi Pavithra,
The sample that you have provided is not working. I have been trying for few days without succeeding. I'm using Visual studio 2022 with angular version 12. I'll appreciate it if you could either recreate or provide any sample (connected to database) using Visual Studio 2022.
Regards Charles
Hi Charles,
We have prepared a new sample based on your update. Please refer to the attached sample for more information. If you still having any issues, please share the below details that will be helpful or us to provide a better solution as early as possible.
Regards,
Pavithra S
Hi Pavithra,
When I select a row on the grid for editing the value of the dropdown list clears. I want the dropdown list to retain its original value when l select a row for editing. Kindly assist. See link attached below
https://stackblitz.com/edit/angular-kqu7vy-rmhdpx?file=app.component.ts,app.component.html
How can l change grid column header text to bold?
Hi Charles,
Query#1: When I select a row on the grid for editing the value of the dropdown list clears. I want the dropdown list to retain its original value when l select a row for editing.
To show the corresponding field value in the DropDownList component while editing, you need to set “value” or “text” property with the field value. Since you are returning the “this.segmentObj.text” inside the “read” function you need to set the “text” property to achieve your requirement. Please refer to the below code example and API link for more information.
write: (args) => { this.segmentObj = new DropDownList({ dataSource: this.segment, fields: { value: 'segmentId', text: 'segmentName' }, text: args.rowData[args.column.field], placeholder: 'Select a Segment', floatLabelType: 'Never', }); this.segmentObj.appendTo(this.segmentElem); }, };
|
Query#2: How can l change grid column header text to bold?
You can set the “font-weigth” style to the header text by using the below style.
.e-grid span.e-headertext { font-weight: bold; }
|
Please get back to us if you need further assistance.
Regards,
Pavithra S
Hi Pavithra,
Thank you for the solution that you had provided. It works with local data binding, but l intend to connect the grid drop down with the server. So, I've tried the codes below but didn't work as expected. Can you show me how to load the grid drop down with data from the server?
2. I want to upload the files while clicking the submit button of the form.
I have tried by calling the upload method of the EJ2 uploader component inside the submit button click event but it seems that i'm might not doing it wrong. Kindly assist
https://stackblitz.com/edit/angular-nqk33p?file=app.component.ts
Hi Charles,
Query#1: Can you show me how to load the grid drop down with data from the server?
You can set the dataSource from the server inside the “then” function as in the below code example.
write: (args) => { this.segmentObj = new DropDownList({ fields: { value: 'ShipCountry', text: 'ShipCity' }, text: args.rowData[args.column.field], placeholder: 'Select a Segment', floatLabelType: 'Never', }); new DataManager({ url: 'https://ej2services.syncfusion.com/production/web-services/api/Orders', }) .executeQuery(new Query().take(6)) .then((e: any) => { this.segmentObj.dataSource = e.result.result as object[]; this.segmentObj.appendTo(this.segmentElem); }); }, };
|
Query#2:I want to upload the files while clicking the submit button of the form.
We have created a new forum under your account regarding the EJ2 Uploader component. Please follow that for more updates.
Note: Please create a new forum for new queries for a better follow-up in the future.
Regards,
Pavithra S
Hi Pavithra,
The codes that you provided didn't work. The error is found on this line this.segmentObj.dataSource = e.result.result as object[];
Hi Charles,
To overcome the reported issue, we suggest checking the result from the API call inside the “then” function and based on the result value set the dataSource property for the DropDownList.
// check the response “e” here and if e.result contains the records then set it to the ‘dataSource’ // setting “e.result” is given as an example purpose only. You can change the below line base on your API response
this.segmentObj.dataSource = e.result as object[];
|
Regards,
Pavithra S
Hi Pavithra,
I have tried everything that you had asked me to do but is still didn't work. I'll appreciate it if you can get me any other options of loading grid's dropdownList with data from the server.
Regards
Charles
Hi Charles,
You can also use the EJ2 Adaptors to fetch data from the server. Please refer to the below code example and documentation link for more information.
this.segmentObj = new DropDownList({ dataSource: new DataManager({ url: 'https://services.odata.org/V4/Northwind/Northwind.svc/Orders', adaptor: new ODataV4Adaptor(), crossDomain: true, }), query: new Query().take(6), fields: { value: 'CustomerID', text: 'CustomerID' }, text: args.rowData[args.column.field], placeholder: 'Select a Segment', floatLabelType: 'Never', }); this.segmentObj.appendTo(this.segmentElem);
|
Documentation: https://ej2.syncfusion.com/angular/documentation/data/adaptors/#web-api-adaptor
https://ej2.syncfusion.com/angular/documentation/drop-down-list/data-binding/#binding-remote-data
If you are still facing the issue, please share an issue reproducible sample with a simple API backend which will be helpful for us to validate the issue and provide a better solution as early as possible.
Regards,
Pavithra S
Hi Pavithra,
Thank you for all your efforts towards helping me solve my problems. I have fixed the problem. All this while l didn't call [edit]='segmentParams' in my html component. That was the problem.
Regards
Charles
Hi Charles,
We are glad to hear that you have achieved your requirement! Please get back to us if you need further assistance on this.
Regards,
Pavithra S
Hi Pavithra,
I'm having issue trying to load data from the database to drop down list. I have tried the codes below but was not successful. Kindly assist
prefixController using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Syncfusion.EJ2.Base; using project11.Models; namespace project11 .Controllers { public class prefixController : Controller { private readonly bhfdbContext _context; public prefixController(bhfdbContext context) { _context = context; } public IActionResult Index() { return View(); } public IActionResult Privacy() { return View(); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult UrlDatasource([FromBody] DataManagerRequest dm) { IEnumerable int count = DataSource.Cast return Json(new { result = DataSource, count = count }); } } } |
app.component.ts
this.prefixParams = { create: () => { this.prefixElem = document.createElement('input'); return this.prefixElem; }, read: () => { return this.prefixObj.text; }, destroy: () => { this.prefixObj.destroy(); }, write: (args) => { this.prefixObj = new DropDownList({ fields: { value: 'PrefixId', text: 'PrefixName' }, text: args.rowData[args.column.field], placeholder: 'Select a title', floatLabelType: 'Never', }); new DataManager({ url: 'prefix/UrlDatasource', adaptor: new UrlAdaptor() }) .executeQuery(new Query().take(6)) .then((e: any) => { this.prefixObj.dataSource = e.result; this.prefixObj.appendTo(this.prefixElem); }); }, }; |
Hi Charles,
We have tried the same code you shared with us to reproduce the issue, but the DropDownList is loaded, and the editing is working fine. Please refer to the attached screenshot and sample for more information.
From your code, we suspect that the Database is not returning the data inside the “UrlDatasource” action. So, we suggest ensuring that the data is assigned properly in “DataSource” inside the “UrlDatasource” action. If you are still facing the issue, please share an issue reproducible sample with a working backend which will be helpful for us to validate the issue and provide a better solution as early as possible.
Regards,
Pavithra S
Hi Pavithra,
My aim to to load drop down list with data from Prefix table in the database. I have two controllers is CustomerController and PrefixController with just a single grid control. The grid will load all data from the customet table in the database. The drop down edit in the grid is to load all data from Prefix table in the database. See attached file where l have modified your sample to imitate my scenario. Kindly assist
Hi Charles,
Thanks for sharing the sample.
We have validated the sample and found that you are trying to fetch data using the “UrlAdaptor” from a Web API endpoint by defining normal action inside the “OrderControler”. This is the cause of the reported issue. If you want to fetch data from the API endpoint, we suggest the “WebApiAdaptor” which expected the server response as “Items” and “Counts” pair. Please refer to the below code example and screenshot for more information.
new DataManager({ url: 'api/Order', adaptor: new WebApiAdaptor() }) .executeQuery(new Query().take(6)) .then((e: any) => { this.prefixObj.dataSource = e.result; this.prefixObj.appendTo(this.prefixElem); }); |
// GET: api/Orders [HttpGet]
public object Get() { var data = OrdersDetails.GetAllRecords(); return new { Items = data, Count = data.Count() };
} |
|
If you are still facing the issue, please ensure the below scenarios to validate the issue based on which we can suggest a suitable adaptor to achieve your requirement.
Regards,
Pavithra S
Hi pavithra,
I'm not using Web api endpoint. I'm using the normal action to populated my grid from the database which works fine. The drop down is not showing data from the base. I use the example you provided past week but is still not work.
Regards
Charles
Hi Charles,
As we requested in our previous update, please share the below details that will be helpful for us to provide a better solution as early as possible.
https://www.geeksforgeeks.org/how-to-make-ajax-call-from-javascript/
Regards,
Pavithra S
Hi Pavithra,
I have explored so many of your documentations on drop down but couldn't find a suitable help for this problem. I have a drop down and a textbox. The drop down is bind to a datasource, so when l select an item from drop down the textbox should be populated with its corresponding value from the database. For example
Drop down Textbox
EmployeeId Firstname
001 Mark
002 Mary
003 Sabina
So, when l select EmployeeId ‘002’ from the drop down then ‘Mary’ would be displayed in the textbox. Kindly assist
export class EmployeeComponent implements OnInit {
reactForm: FormGroup; public textboxValue; public height: string = '250px';
constructor(public service: employeeService, private formBuilder: FormBuilder) { }
ngOnInit() { this.textboxValue=''; this.reactForm = new FormGroup({ 'EmployeeId': new FormControl('', [FormValidators.required]), 'FirstName': new FormControl('', [FormValidators.required]) });
let formId: HTMLElement = <HTMLElement>document.getElementById('formId'); document.getElementById('formId').addEventListener( 'submit', (e: Event) => { e.preventDefault(); if (this.reactForm.valid) { this.service.postemployee(this.reactForm.value).subscribe( res=>{ this.reactForm.reset(); }, err => { console.log(err);} ) } else { // validating whole form Object.keys(this.reactForm.controls).forEach(field => { const control = this.reactForm.get(field); control.markAsTouched({ onlySelf: true }); }); } }); }
public data: DataManager = new DataManager({ url: 'api/Employees', adaptor: new WebApiAdaptor() });
public fields: Object = { text: 'FirstName', value: 'FirstName' }; public query: Query = new Query().from('Employees').select(['FirstName']).take(6);; public WaterMark: string = "Select a name";
get EmployeeId() { return this.reactForm.get('EmployeeId'); } get FirstName() { return this.reactForm.get('FirstName'); }
}
|
<div class="formtitle"> <span>Add Next-of-kin Details</span> </div> <form id="formId" [formGroup]="reactForm" #formDir="ngForm" class="form-horizontal" novalidate=""> <div class="form-row"> <div class="form-group col"> <div class="e-float-input" id='content' style="margin: 0px auto; width:300px; padding-top: 20px;"> <ejs-dropdownlist [dataSource]='data' [(value)]='value' id="employees" type="text" formControlName="EmployeeId" [fields]='fields' [query]='query' [popupHeight]='height' sortOrder='Ascending'> </ejs-dropdownlist> <span class="e-float-line"></span> <label class="e-float-text">Employee ID</label> </div> <div *ngIf="EmployeeId.errors"> <div *ngIf="EmployeeId.errors.required && EmployeeId.touched" class="e-error"> This field is required. </div> </div> </div> <div class="form-group col"> <div class="e-float-input"> <input id="FirstName" type="text" [(ngModel)]="value" formControlName="FirstName"/> <span class="e-float-line"></span> <label class="e-float-text">First Name</label> </div> <div *ngIf="FirstName.errors "> <div *ngIf="FirstName.errors.required && FirstName.touched" class="e-error"> Please enter first name. </div> </div> </div>
<div class="row"> <div style="width: 320px;margin:0px auto;height: 100px;padding-top: 25px;"> <div style="display: inline-block;"> <button id="validateSubmit" class="samplebtn e-control e-btn e-primary" type="submit" style="height:40px;width: 150px;" data-ripple="true">Add Customer</button> </div> <div style="float: right;"> <button id="resetbtn" class="samplebtn e-control e-btn" type="reset" style="height:40px;width: 150px;" data-ripple="true">Clear</button> </div> </div> </div> </form>
|
Regards
Charles
Hi Charles,
Since the reported query is related to EJ2 DropDownList component, we have created a new forum “Branched from forum-173400” under your account. For more updates regarding the above query please follow up on the new one.
Also, we request you to create a new forum for new queries in the future. This will help for better follow up.
Regards,
Pavithra S
Hi Charles,
If you want to change the text box value while changing a dropdown list value, then you can achieve your requirement by adding the “change” event to the DropDownList and inside this event, you can set the textbox value. Please refer to the below code example for more information.
write: (args) => { this.prefixObj = new DropDownList({ fields: { value: 'PrefixId', text: 'PrefixName' }, . . . change: (args) => { // here this.grid is Grid instance and “CustomerID” is the corresponding field of the required textbox this.grid.editModule.formObj.element.querySelector("#" + this.grid.element.id + "CustomerID").ej2_instances[0].value = args.itemData.PrefixId; } }); this.prefixObj.appendTo(this.prefixElem);
}
|
Please get back to us if you need further assistance on this.
Regards,
Pavithra S