Hi,
I really need to be able to display data as chips in one particular column of react data grid
Any help to achieve this would be really appreciated
Thank you
Eric
export class Default extends SampleBase {
. . .
chipTemplate (args) {
var shipCountry = args.ShipCountry.split(',');
if (args.ShipCountry) {
return (<ChipListComponent id="chip-avatar">
<ChipsDirective>
{shipCountry.map((value, index) => {
return <ChipDirective key={index} cssClass={[this.countryData.find((e, index)=>{return e.Country === value}).Color.toLowerCase() + " " + "e-chips"]} text={value}></ChipDirective>
})}
</ChipsDirective>
</ChipListComponent>);
}
else {
return '';
}
}
render() {
return (
<div className="control-pane">
<div className="control-section">
<GridComponent
. .
<ColumnDirective
field="ShipCountry"
headerText="Ship Country"
edit={this.editparams}
template={this.chipTemplate.bind(this)}
width="150"
/>
</ColumnsDirective>
<Inject services={[Edit, Toolbar]} />
</GridComponent>
</div>
</div>
);
}
} |
Hi Thiyagu,
Thank you for your reply, it almost answer my requirement except that I'm not using a multiSelect, I have an array coming from the dataSource for that column and I want to display all the items from the array of each row.
I hope you understand what I mean
Thank you
Eric
chipTemplate(args) {
var shipCountry = args.ShipCountry;
if (args.ShipCountry) {
return (
<ChipListComponent id="chip-avatar">
<ChipsDirective>
{shipCountry.map((value, index) => {
return <ChipDirective key={index} text={value} />;
})}
</ChipsDirective>
</ChipListComponent>
);
} else {
return '';
}
}
actionBegin(args) {
if (args.requestType === 'save') { // we have defined required array value based on that modified shipCountry value
args.data.ShipCountry = args.data.ShipCountry.split(',');
}
}
|
Hi Thiyagu,
This solution solved my issue, thanks
but if I wanted to only display the 2 first items from the array and add a little tag displaying the amount of items not displaying, for example, if I have 5 items in the array, I want to display the 2 first items since the remaining of 5 minus 2 is 3, I want to display a little tag with a 3 on it.
I hope it makes sens the way I'm explaining it
Thank you
Eric
export class Default extends SampleBase {
data = [
{
OrderID: 10248,
CustomerID: 'VINET',
ShipCountry: ['France', 'Germany']
},
{
OrderID: 10249,
CustomerID: 'TOMSP',
ShipCountry: ['Germany', 'Brazil', 'France']
},
{
OrderID: 10250,
CustomerID: 'HANAR',
ShipCountry: ['Brazil', 'Belgium']
},
{
OrderID: 10251,
CustomerID: 'VICTE',
ShipCountry: ['France', 'Switzerland']
}
];
editOptions = { allowEditing: true, allowAdding: true, allowDeleting: true };
toolbarOptions = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
chipTemplate(args) {
// here we have sliced the first two items and stored in a variable
var shipCountry = args.ShipCountry.slice(0,2);
if (args.ShipCountry) {
return (
<div>
<ChipListComponent id="chip-avatar">
<ChipsDirective>
{shipCountry.map((value, index) => {
return <ChipDirective key={index} text={value} />;
})}
</ChipsDirective>
</ChipListComponent>
//showing the count of remaining items in a button
<ButtonComponent cssClass='e-primary'>{args.ShipCountry.length>2 ? args.ShipCountry.length-2: 0}</ButtonComponent>
</div>
);
} else {
return '';
}
}
actionBegin(args) {
if (args.requestType === 'save') {
args.data.ShipCountry = args.data.ShipCountry.split(',');
}
}
render() {
return (
<div className="control-pane">
<div className="control-section">
<GridComponent
dataSource={this.data}
editSettings={this.editOptions}
toolbar={this.toolbarOptions}
actionBegin={this.actionBegin.bind(this)}
. . .
<ColumnDirective
field="ShipCountry"
headerText="Ship Country"
template={this.chipTemplate.bind(this)}
width="150"
/>
</ColumnsDirective>
<Inject services={[Edit, Toolbar]} />
</GridComponent>
</div>
</div>
);
}
} |
Hi Manivel,
That is almost exactly what I wanted to achieve, except that I would like the tag with the number on the same line that the 2 chips not under.
Thank you
Eric
Hi,
I also have another issue, I'm using column commands to display a delete button in one of the columns and I didn't find a way to customize the delete confirmation message, any help would be appreciated.
Thank you
Eric
chipTemplate(args) {
// here we have sliced the first two items and stored in a variable
var shipCountry = args.ShipCountry.slice(0, 2);
// if the length is more than 2 then we have added one more item to show how many items are more.
shipCountry =
args.ShipCountry.length > 2
? shipCountry.concat((args.ShipCountry.length - 2).toString())
: shipCountry;
if (args.ShipCountry) {
return (
<div>
<ChipListComponent id="chip-avatar" width="150px">
<ChipsDirective>
{shipCountry.map((value, index) => {
return <ChipDirective key={index} text={value} />;
})}
</ChipsDirective>
</ChipListComponent>
</div>
);
} else {
return '';
}
}
|
L10n.load({
'en-US': {
grid: {
ConfirmDelete: 'Click Ok to delete the record'
}
}
});
|
Hi Joseph,
Thank you for your reply it solved my first issue and part of my second issue as well but for the confirmation message, I would like to display the value of the first column (name) in the confirmation message for the row I'm deleting, for example if I want to delete the the first row and the name in the first column for that row is John Doe, I want to display a confirmation message as follow, "You're about to delete access for user: John Doe but if I want to delete another row with name Jane Austin, the confirmation message should display as follow, "You're about to delete access for user: Jane Austin
Thank you
Eric
toolbarClick(args) {
if (
args.item.text == 'Delete' &&
args.item.id == this.grid.element.id + '_delete'
) {
var selectedRecords = this.grid.getSelectedRecords();
if (selectedRecords.length > 0) {
var customerId = selectedRecords[0].CustomerID;
this.grid.defaultLocale.ConfirmDelete =
"You're about to delete access for user: " + customerId;
}
}
}
commandClick(args) {
this.grid.defaultLocale.ConfirmDelete =
"You're about to delete access for user: " + args.rowData.CustomerID;
}
|
Hi Joseph,
Thank you very much, this is exactly what I needed, it completely solved my issue.
I have another issue maybe you can help me with, when I add a new row I want the trash button to automatically be added to it, I don't know if it's possible or not.
Thank you
Eric
Hi Joseph,
The issue with the trash button is resolved but I have another issue, I need the first column of the new row, which is the username column, to act as a search field, what I mean is for example, I add a new row and type the username of the user I want to add in the first column and if the user is in the database, it automatically fill the remaining columns or the row with the data.
I hope it makes sense the way I explained it
THank you
Eric
Hi Joseph,
Thanks for your reply, to answer your questions, I want to display the details of other columns when I type the user name data only and press the enter key and I don't have any other columns set as Primary Key.
Thank you
Eric
Hi Joseph,
Thank you for your answer but it doesn't answer question as a remainder here what I need.
I need the first column of the new row, which is the username column, to act as a search field, what I mean is for example, I add a new row and type the username of the user I want to add in the first column and if the user is in the database, it automatically fill the remaining columns or the row with the data.
Is it possible to do it with Syncfusion EJ2 react Grid ??
Thank you
Eric
Hi Joseph,
No there wont be any duplicate value for the username field.
Thank you
Eric
public onActionBegin(args) {
if (args.requestType === 'save') {
if (args.data.OrderID === undefined || args.data.OrderID === null) {
args.cancel = true;
var tempData = args.data;
(this as any).grid.showSpinner();
var ajax = new Ajax();
ajax.type = "POST"
ajax.url = "/Home/GetCustomerData"
var customerId = { CustomerID: args.data.CustomerID };
ajax.data = JSON.stringify(customerId);
ajax.send();
ajax.onSuccess = (result) => {
var resultData = JSON.parse(result);
if (resultData.IsSuccess) {
tempData.OrderID = 10000 + resultData.Count + 1;
tempData.EmployeeID = resultData.OrderList.EmployeeID;
tempData.Freight = resultData.OrderList.Freight;
tempData.OrderDate = resultData.OrderList.OrderDate;
tempData.ShipCity = resultData.OrderList.ShipCity;
(this as any).grid.addRecord(tempData);
}
(this as any).grid.hideSpinner();
}
}
}
}
|
HI Joseph,
Thank you for your reply but there is only a tiny problem with your provided answer it is that I'm in React not in ASP.NET, can you translate it to React please ?
Thank you
public onActionBegin(args) {
if (args.requestType === 'save' && args.action === 'add') {
if (args.data.OrderID === undefined || args.data.OrderID === null) {
args.cancel = true; // cancel the normal save process.
var tempData = args.data; // assign the data of the new row to a temp variable.
(this as any).grid.showSpinner(); // show the spinner to the grid.
var ajax = new Ajax();
ajax.type = "POST"
ajax.url = "/Home/GetCustomerData"
var customerId = { CustomerID: args.data.CustomerID };
ajax.data = JSON.stringify(customerId);
ajax.send(); // send a HTTP request to the server side.
ajax.onSuccess = (result) => { // in the success event of the request assign the values got from the server side to the tempdata.
var resultData = JSON.parse(result);
if (resultData.IsSuccess) {
tempData.OrderID = 10000 + resultData.Count + 1;
tempData.EmployeeID = resultData.OrderList.EmployeeID;
tempData.Freight = resultData.OrderList.Freight;
tempData.OrderDate = resultData.OrderList.OrderDate;
tempData.ShipCity = resultData.OrderList.ShipCity;
(this as any).grid.addRecord(tempData); // call the add record method and pass the tempdata to create a new row.
}
(this as any).grid.hideSpinner(); // hide the spinner from the grid.
}
}
}
}
|