dsynkd
dsynkd

Reputation: 2145

Why is this xml not displayed?

My ajax function for JQGrid returns this piece of xml:

<?xml version='1.0' encoding='utf-8' ?>
<rows>
    <row id='1'>
        <cell>Darren Sadr</cell>
        <cell>12345678</cell>
        <cell>01/12/1995</cell>
        <cell>
            <select>
                <option value='1' selected>Cypress Falls</option>
                <option value='2'>Cypress Lakes</option>
                <option value='3'>Cypress Ridge</option>
                <option value='4'>Cypress Fair</option>
                <option value='0'>None</option>
            </select>
        </cell>
        <cell>8325731944</cell>
        <cell>[email protected]</cell>
        <cell>8325731944</cell>
        <cell>[email protected]</cell>
        <cell>12/09/2013</cell>
        <cell>12/09/2014</cell>
        <cell>
            <select>
                <option selected>Unverified</option>
                <option>OK</option>
                <option>NoShow</option>
                <option>Archived</option>
            </select>
        </cell>
        <cell>false</cell>
        <cell>0</cell>
        <cell>0</cell>
    </row>
    <row id='2'>
        <cell>Darren Vortex</cell>
        <cell>87654321</cell>
        <cell>12/01/1995</cell>
        <cell>
            <select>
                <option value='1' selected>Cypress Falls</option>
                <option value='2'>Cypress Lakes</option>
                <option value='3'>Cypress Ridge</option>
                <option value='4'>Cypress Fair</option>
                <option value='0'>None</option>
            </select>
        </cell>
        <cell>8326380419</cell>
        <cell>[email protected]</cell>
        <cell>8326380419</cell>
        <cell>[email protected]</cell>
        <cell>12/09/2013</cell>
        <cell>12/09/2014</cell>
        <cell>
            <select>
                <option selected>Unverified</option>
                <option>OK</option>
                <option>NoShow</option>
                <option>Archived</option>
            </select>
        </cell>
        <cell>false</cell>
        <cell>0</cell>
        <cell>0</cell>
    </row>
</rows>

However, the grid doesn't display anything.
If I remove the cells with the 'select' element in them, the grid displays everything else correctly.
Why is that? And how can I get it to display the select elements?

Upvotes: 0

Views: 94

Answers (3)

dsynkd
dsynkd

Reputation: 2145

I had to do the sneakiest thing:
Replaced all '<' and '>' characters inside the grid cells by some other character set (e.g the HTML code) to prevent tags from being stripped by jqGrid.
Then used the custom formatter function to return the value with the html codes replaced with the actual characters.
Woot?

Upvotes: 1

Oleg
Oleg

Reputation: 221997

I don't want to discuss why you what to place HTML fragments as part of XML data. I want just answer how to fix the data so that there could be displayed in the grid.

I personally would recommend you to use

<option selected='selected'>Unverified</option>

instead of

<option selected>Unverified</option>

Nevertheless it's not real error in your XML code. What you really need to do is to use CDATA for <cell> content if the data contains HTML fragments:

<?xml version='1.0' encoding='utf-8' ?>
<rows>
    <row id='1'>
        <cell>Darren Sadr</cell>
        <cell>12345678</cell>
        <cell>01/12/1995</cell>
        <cell>
            <![CDATA[<select>
                <option value='1' selected='selected'>Cypress Falls</option>
                <option value='2'>Cypress Lakes</option>
                <option value='3'>Cypress Ridge</option>
                <option value='4'>Cypress Fair</option>
                <option value='0'>None</option>
            </select>]]>
        </cell>
        <cell>8325731944</cell>
        <cell>[email protected]</cell>
        <cell>8325731944</cell>
        <cell>[email protected]</cell>
        <cell>12/09/2013</cell>
        <cell>12/09/2014</cell>
        <cell>
            <![CDATA[<select>
                <option selected='selected'>Unverified</option>
                <option>OK</option>
                <option>NoShow</option>
                <option>Archived</option>
            </select>]]>
        </cell>
        <cell>false</cell>
        <cell>0</cell>
        <cell>0</cell>
    </row>
    <row id='2'>
        <cell>Darren Vortex</cell>
        <cell>87654321</cell>
        <cell>12/01/1995</cell>
        <cell>
            <![CDATA[<select>
                <option value='1' selected='selected'>Cypress Falls</option>
                <option value='2'>Cypress Lakes</option>
                <option value='3'>Cypress Ridge</option>
                <option value='4'>Cypress Fair</option>
                <option value='0'>None</option>
            </select>]]>
        </cell>
        <cell>8326380419</cell>
        <cell>[email protected]</cell>
        <cell>8326380419</cell>
        <cell>[email protected]</cell>
        <cell>12/09/2013</cell>
        <cell>12/09/2014</cell>
        <cell>
            <![CDATA[<select>
                <option selected='selected'>Unverified</option>
                <option>OK</option>
                <option>NoShow</option>
                <option>Archived</option>
            </select>
        ]]></cell>
        <cell>false</cell>
        <cell>0</cell>
        <cell>0</cell>
    </row>
</rows>

After such changes jqGrid should be able to display the data. See the demo. It displays

enter image description here

Upvotes: 0

Andrii Horda
Andrii Horda

Reputation: 180

You have grammatically unexpected character '>' on

<option value='1' selected>Cypress Falls</option>.

'selected' attribute should be specified. For example:

<option value='1' selected='true'>Cypress Falls</option>.

Upvotes: 0

Related Questions