|
created:function(args){
this.keyConfigs.enter = '' // remove the enter key’s action in the grid
}
|
|
-------
var grid = new ej.grids.Grid({
dataSource: [{
OrderID: 10250,
CustomerID: "HANAR",
Freight: 65.83,
ShipCity: "Rio de Janeiro<br/>uyyuyuu<br/>ghdaj" // use the BR element to break the lines
}],
allowPaging: true,
height: '300px',
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true },
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 100, isPrimaryKey: true },
{ field: 'Freight', headerText: 'Freight', format: 'C2', width: 120 },
{
field: 'ShipCity', headerText: '<span>ShipCity</span>', disableHtmlEncode: false, width: 150, edit: {
-----}}]
----------
});
grid.appendTo('#Grid');
|
Hello support,
I do have exactly the same problem as Jim describes.
When I use a multiline textbox, data sent to the server does include a line break (CR). This is ok for me. I can save this data in my database.
Afterwards I can use this data to display the value somewhere on my website when I replace the CR with HTML BR
on the fly. This is ok.
But in the grid, the multiline text is displayed as a single line text when the grid is not in edit mode.
This will cause confusion to the editor, as the line break is only visible when the grid is in edit mode.
What can we do?
Regards,
Stephan
|
[index.js]
var grid = new ej.grids.Grid({
dataSource: data,
columns: [
{ field: 'CustomerID', headerText: 'Customer ID', disableHtmlEncode: false, width: 120 },
---
]
});
grid.appendTo('#Grid');
|
Hi support,
please try this yourself.
It is easy to reproduce.
The code of the grid is:
The data sent to the grid is:
(I have replaced the "backslash n" with ":CR:" here, because the forum does not show it. The server of course sends a "backslash n" to the grid)
{
"result": [
{
"coursecalblockid": 1,
"caption": "Test1",
"DateFromLocalized": "14.08.2021",
"DateToLocalized": "22.08.2021",
"DateFromJSDate": "2021-08-14T00:00:00+02:00",
"DateToJSDate": "2021-08-22T00:00:00+02:00",
"NoOfDays": 9,
"location": "First row:CR:Second row",
"priceperday": 55
},
{
"coursecalblockid": 2,
"caption": "Test 2",
"DateFromLocalized": "01.10.2021",
"DateToLocalized": "04.10.2021",
"DateFromJSDate": "2021-10-01T00:00:00+02:00",
"DateToJSDate": "2021-10-04T00:00:00+02:00",
"NoOfDays": 4,
"location": "First row:CR:Second row",
"priceperday": 0
}
],
"count": 2
}
Here you see a screenshot of the issue.
The first row of the gird is in inline edit mode and you can see, that the data contains two lines with one CR.
The second row of the grid contains the same data as the first, but is not in edit mode. Here you can see, that the CR has no effect.
Activating HTML does not help at all, because the CR will not be considered as a BR-tag. So there will be no change on the screen.
And if I replace the CR with a BR-tag on the server side and send it back to the grid, the text is displayed correct at non edit mode, but as soon as I enter the edit mode, the BR-tag is visible and the user gets confused.
Regards,
Stephan
|
[index.js]
var grid = new ej.grids.Grid({
dataSource: [
{
OrderID: 10250,
CustomerID: 'HANAR',
Freight: 65.83,
location: 'First row\nSecond row', // maintain ‘\n’ in the grid dataSource
},
],
columns: [
---
{
field: 'location',
headerText: '<span style="color:red">ShipCity</span>',
disableHtmlEncode: false,
valueAccessor: valueAccessor,
width: 150,
edit: {
---
}
},
],
created: function (args) {
this.keyConfigs.enter = '';
},
});
grid.appendTo('#Grid');
function valueAccessor(field, data, column) {
var value = data[field];
// replace the /n with the <br>
return value.split('\n').join('<br>');
}
|
Hi support,
many thanks.
This works now, although it is a little bit complicated.
It would be better, if this would be a built in feature.
Please include the solution in your documentation.
Regards,
Stephan
Hi support,
I found an issue with your solution.
If I want to make a new entry, the valueAccessor function fails, because the variable value is undefined.
So I extend your code as follows
Regards,
Stephan