LCJ
LCJ

Reputation: 22652

jqGrid trims multiple spaces

I have a jqGrid displaying local data. The RoutingID column has multiple spaces in the source data – but when rendered in the jqGrid it has only one space before the character “54”.

Is there a way to display the data in the Grid as it is in the source – maintaining the same spaces in the source?

var data =[{"__type":"MyWebNoCompile.Routing","RoutingID":"C161-58          54","Destinations":"11 - My INC.-OUTER"},{"__type":"MyWebNoCompile.Routing","RoutingID":"C161-90B         54","Destinations":"11 - MY INC.-OUTER"}]
             alert(data);

            $("#grid").jqGrid({
                datastr: data,
                datatype: "jsonstring",
                colNames: ['Routing ID', 'Destinations'],
                colModel: [
                    { name: 'RoutingID', index: 'RoutingID', width:150 },
                    { name: 'Destinations', index: 'Destinations', width:400 }
                ],
                rowNum: 10,
                viewrecords: true,
                gridview: true,
                height: "auto",
                loadonce: true
            });

REFERENCES

  1. Custom Formatter
  2. Predefined Formatter

enter image description here

UPDATE

Solved by adding a custom formatter as shown below

function mySpacePreserveFormatter (cellvalue, options, rowObject)
   {
             return '<pre>' + cellvalue + '</pre>';
   }

and using it as

name: 'RoutingID', index: 'RoutingID', formatter:mySpacePreserveFormatter

About pre tag from http://www.w3schools.com/tags/tag_pre.asp

The tag defines preformatted text. Text in a element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and line breaks.

Upvotes: 0

Views: 875

Answers (1)

Andy Newman
Andy Newman

Reputation: 281

HTML by specification strips out additional spaces - this is not a jQuery issue.

To keep whitespace, you may wrap the content in <pre> tags

Upvotes: 1

Related Questions