[app.component.html]
<ejs-grid [dataSource]='data' height='350' [allowPaging]=true (rowSelected)='rowSelected($event)'>
<e-columns>
----
</e-columns>
</ejs-grid>
-----------------------------------------------------------------------------------------------------
[app.component.ts]
export class AppComponent {
public data: Object[] = [];
ngOnInit(): void {
this.data = orderDetails;
}
rowSelected(args){
console.log(args.data); // you can get the selected record in the below argument
}
}
|
Hi Isanka,
Greetings from Syncfusion support.
We can get the selected row data in the rowSelected event of Grid.
[app.component.html]
<ejs-grid [dataSource]='data' height='350' [allowPaging]=true (rowSelected)='rowSelected($event)'><e-columns>
----
</e-columns></ejs-grid>
-----------------------------------------------------------------------------------------------------[app.component.ts]
export class AppComponent {public data: Object[] = [];
ngOnInit(): void {this.data = orderDetails;}rowSelected(args){console.log(args.data); // you can get the selected record in the below argument}}
We have prepared a simple sample in the following link.
Refer the help documentation.
If we misunderstood your query then please get back to us.
Regards,Thavasianand S.
[app.component.html]
<button id="strikerow">Strike out the selected row</button>
<button id="getselectedrow">Get the selected record</button>
<ejs-grid [dataSource]='data' #grid height='350' [selectionSettings]='selectionOptions'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right'></e-column>
<e-column field='CustomerName' headerText='Customer Name' width='150'></e-column>
<e-column field='OrderDate' headerText='Order Date' width='130' format="yMd" textAlign='Right'></e-column>
<e-column field='Freight' headerText='Freight' width='120' format='C2' textAlign='Right'></e-column>
<e-column field='ShippedDate' headerText='Shipped Date' width='130' format="yMd" textAlign='Right'></e-column>
<e-column field='ShipCountry' headerText='Ship Country' width='150'></e-column>
</e-columns>
</ejs-grid>
--------------------------------------------------------------
[app.component.ts]
export class AppComponent {
public data: Object[] = [];
public selectionOptions: SelectionSettingsModel;
ngOnInit(): void {
this.data = orderDetails;
this.selectionOptions = { type: 'Multiple', enableSimpleMultiRowSelection: true };
document.getElementById('strikerow').addEventListener('click', function (args) {
var gridObj = document.getElementsByClassName('e-grid')[0]['ej2_instances'][0];
var rows = gridObj.getSelectedRows();
for (var i = 0; i < rows.length; i++) {
var tr = rows[i];
for (var j = 0; j < tr['childElementCount']; j++) {
tr.children[j].classList.add('strikeOut');
}
}
});
document.getElementById('getselectedrow').addEventListener('click', function (args) {
var gridObj = document.getElementsByClassName('e-grid')[0]['ej2_instances'][0];
var selectedrecord = gridObj.getSelectedRecords();
console.log(selectedrecord);
})
}
}
-----------------------------------------------------
[index.html]
<style>
.e-grid .strikeOut {
text-decoration: line-through;
}
</style>
|
Hi Isanka,
We have prepared a sample with your mentioned requirement in the following link.
Refer the below code example.
[app.component.html]
<button id="strikerow">Strike out the selected row</button><button id="getselectedrow">Get the selected record</button><ejs-grid [dataSource]='data' #grid height='350' [selectionSettings]='selectionOptions'><e-columns><e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right'></e-column><e-column field='CustomerName' headerText='Customer Name' width='150'></e-column><e-column field='OrderDate' headerText='Order Date' width='130' format="yMd" textAlign='Right'></e-column><e-column field='Freight' headerText='Freight' width='120' format='C2' textAlign='Right'></e-column><e-column field='ShippedDate' headerText='Shipped Date' width='130' format="yMd" textAlign='Right'></e-column><e-column field='ShipCountry' headerText='Ship Country' width='150'></e-column></e-columns></ejs-grid>--------------------------------------------------------------[app.component.ts]
export class AppComponent {public data: Object[] = [];public selectionOptions: SelectionSettingsModel;ngOnInit(): void {this.data = orderDetails;this.selectionOptions = { type: 'Multiple', enableSimpleMultiRowSelection: true };document.getElementById('strikerow').addEventListener('click', function (args) {var gridObj = document.getElementsByClassName('e-grid')[0]['ej2_instances'][0];var rows = gridObj.getSelectedRows();for (var i = 0; i < rows.length; i++) {var tr = rows[i];for (var j = 0; j < tr['childElementCount']; j++) {tr.children[j].classList.add('strikeOut');}}});document.getElementById('getselectedrow').addEventListener('click', function (args) {var gridObj = document.getElementsByClassName('e-grid')[0]['ej2_instances'][0];var selectedrecord = gridObj.getSelectedRecords();console.log(selectedrecord);})}}-----------------------------------------------------[index.html]
<style>.e-grid .strikeOut {text-decoration: line-through;}</style>
Refer the help documentation.
Regards,Thavasianand S.
Hi Isanka,
As per your suggestion we have prepared a sample, which can able to do strike out, remove strike out and get the strike rows operation using the external button and sample can be viewed in the following link.
Regards,Thavasianand S.
Hi Isanka,
Thanks for your update.
We are able to reproduce the issue in the sample. So, We have modified the sample in the following ink.
Regards,Thavasianand S.
<style>
.e-grid .strikeOut {
text-decoration: line-through;
}
</style>
|
[app.component.ts]
export class AppComponent {
public data: Object[] = [];
public selectionOptions: SelectionSettingsModel;
public flag;
public getstrikedflag = false; //
@ViewChild("grid") public grid: GridComponent;
ngOnInit(): void {
this.data = orderDetails;
this.selectionOptions = { type: 'Multiple', enableSimpleMultiRowSelection: true };
//Get teh striked row detail from Grid
document.getElementById('getstrikedrow').addEventListener('click', function (args) {
this.getstrikedflag = true;
var strikerow = tdelementfind(this);
console.log(strikerow);
this.getstrikedflag = false;
}.bind(this));
//Enable strike row for selected row in Grid
document.getElementById('strikerow').addEventListener('click', function (args) {
this.flag = false;
tdelementfind(this);
}.bind(this));
// Remove the strike row in selected row in Grid
document.getElementById('removestrikerow').addEventListener('click', function (args) {
this.flag = true;
tdelementfind(this);
this.flag = false;
}.bind(this));
// Common method for looping tr td elements of Grid
function tdelementfind(proxy) {
var strikedRows = [];
if (proxy.getstrikedflag)
var rows = proxy.grid.getRows();
else
var rows = proxy.grid.getSelectedRows();
for (var i = 0; i < rows.length; i++) {
var tr = rows[i];
for (var j = 0; j < tr['childElementCount']; j++) {
if (tr.children[j].classList.contains('strikeOut') && proxy.flag) {
tr.children[j].classList.remove('strikeOut'); // Remove the strike row
}
else if (proxy.getstrikedflag) {
if (tr.children[j].classList.contains('strikeOut')) {
strikedRows.push(proxy.grid.currentViewData[i]); // Get the strike row detail
break;
}
else
break;
}
else if (!proxy.flag)
tr.children[j].classList.add('strikeOut'); // Enable strike row for selected record
}
}
return strikedRows;
}
}
}
|