- Home
- Forum
- Angular - EJ 2
- Data Grid Feature
Data Grid Feature
I have a query related to data grid. i have requirement that i have to add a drop down list in data grid e column . On click header text of that e column , drop down list show and when i select one value from drop down , that value should be assign to whole column rows. if you people have the solution then please share with me. i was exploring but did not get. Thanks in advance.
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
RS
Rajapandiyan Settu
Syncfusion Team
December 18, 2020 09:40 AM UTC
Hi Muhammad,
Greetings from Syncfusion support.
Query: On click header text of that e column , drop down list show and when i select one value from drop down , that value should be assign to whole column rows.
We have analyzed your query at our end. you can achieve your requirement by using updateRow method of Grid in the dropdown’s change event.
We have prepared a sample with this requirement. In that sample, we rendered the dropdown control inside the column header by using headerTemplate feature.
In the change event of dropdown, we updated the selected value in the each row of the column by using updateRow() method.
Change event of dropdown: https://ej2.syncfusion.com/angular/documentation/api/drop-down-list#change
updateRow method of Grid: https://ej2.syncfusion.com/angular/documentation/api/grid/#updaterow
|
[app.component.html]
<ejs-grid
#grid
[dataSource]="data"
[editSettings]="editSettings"
[toolbar]="toolbar"
height="350"
>
<e-columns>
<e-column
field="OrderID"
headerText="Order ID"
width="120"
isPrimaryKey="true"
textAlign="Right"
></e-column>
<e-column field="ShipCountry" width="200">
<ng-template #headerTemplate let-data
>Customer ID
<ejs-dropdownlist
id="ddlelement"
#samples
[dataSource]="dddata"
[fields]="fields"
[placeholder]="text"
(change)="dropdownchange($event)"
></ejs-dropdownlist>
</ng-template>
</e-column>
-----
</e-columns>
</ejs-grid>
[app.component.ts]
dropdownchange(args) {
var rows = this.grid.getRows();
var currentViewData = this.grid.getCurrentViewRecords();
for (var i = 0; i < rows.length; i++) {
currentViewData[i]["ShipCountry"] = args.value;
// update the selected value in the current page
this.grid.updateRow(parseInt(rows[0].getAttribute("aria-rowindex")), currentViewData[i]);
}
}
|
getCurrentViewRecords: https://ej2.syncfusion.com/angular/documentation/api/grid/#getcurrentviewrecords
Find the below sample for your reference.
Please get back to us if you need further assistance with us.
Regards,
Rajapandiyan S
Marked as answer
MA
Muhammad Arhum Saleem
December 21, 2020 10:25 AM UTC
Thank you so much. It is working. :)
RS
Rajapandiyan Settu
Syncfusion Team
December 22, 2020 03:40 AM UTC
Hi Muhammad,
We are glad that you have resolved your requirement with the provided solution.
Regards,
Rajapandiyan S
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
- Marked answer
-
MA Muhammad Arhum Saleem
- Dec 17, 2020 05:40 PM UTC
- Dec 22, 2020 03:40 AM UTC