1

So, basically what I'm trying to do is making it so when the server sends back results like:

"Car Boat House"

That jqgrid will populate them in a cell like:

Car
Boat
House

I'm using the css method of telling jqgrid to do multiline on this cell with this:

cellattr : function(rowId, tv, rawObject, cm, rdata) {
    return 'style="white-space: normal"';
}

Is there any way to do this? Some kind of "preFill" method for jqGrid I didn't see that would let me substitute:

" "

for

"<br/>" 

on the fly?

I had success forcing my server to jam in the break as the delimiter, but I wept as I wrote it and had to remove it immediately for fear of bursting into flames for sinful coding.

Raevik
  • 1,945
  • 9
  • 32
  • 53

3 Answers3

3

Pass the value of the cell to a formatter function. See http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter

function myformatter ( cellvalue, options, rowObject )
{
  return cellvalue.replace(/\s/,'<br />');
}
Josh Brule
  • 116
  • 4
  • This looks like it will work. Thanks! I should have seen that custom formatter in the documentation. I will say the only issue I'm having with it is that "replace" appears to find the first instance, replace it, then exit. I need like a replaceAll... – Raevik Mar 22 '12 at 20:24
  • 1
    Ended up going with cellvalue.split(' ').join('
    ');
    – Raevik Mar 22 '12 at 20:27
  • Add global flag "g" to pattern. return cellvalue.replace(/\s/g,'
    ');
    – Josh Brule Mar 22 '12 at 20:28
  • 1
    @Josh: I would better recommend to use `beforeProcessing` for the modification of the data (see the example in [the answer](http://stackoverflow.com/a/9722466/315935) or [this one](http://stackoverflow.com/a/9183407/315935)). The main advantage is: you can any formatter which you need. Additionally if you would use recommended option `autoencode: true` the data having symbols `<` or `>` in the text will be displayed correctly and will be not interpreted as HTML data. – Oleg Mar 22 '12 at 22:17
  • 1
    @Brent: Look at the comment which I wrote to Josh. – Oleg Mar 22 '12 at 22:17
1

try using :

return 'style="text-wrap: normal"';

Update, or you could try this also:

return 'style="word-wrap:break-word"';
tusar
  • 3,364
  • 6
  • 37
  • 60
  • That doesn't actually force a newline or break between values. It sets a text wrap based on the width of the column :/ – Raevik Mar 22 '12 at 20:11
0

Instead of applying css to the grid after rendering. Try applying css to the table,

#tableID tr td {
    white-space: normal;
}
Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134