0

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>darrensadr@gmail.com</cell>
        <cell>8325731944</cell>
        <cell>darrensadr@gmail.com</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>darrenvortex@gmail.com</cell>
        <cell>8326380419</cell>
        <cell>darrenvortex@gmail.com</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?

dsynkd
  • 1,999
  • 4
  • 26
  • 40
  • possible duplicate of [is an xml attribute without value valid?](http://stackoverflow.com/questions/6926442/is-an-xml-attribute-without-value-valid) – Kevin B Dec 11 '13 at 16:54
  • Not really. I'd like to learn how to display select elements inside the grid. – dsynkd Dec 11 '13 at 17:41
  • My point was your xml is invalid. Make it valid and it should begin to work. – Kevin B Dec 11 '13 at 18:46

3 Answers3

1

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?

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
dsynkd
  • 1,999
  • 4
  • 26
  • 40
0

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>.

Andrii Horda
  • 170
  • 1
  • 16
  • Indeed that was the problem, but now instead of a Select element, I get all the option values in a string: "Cypress FallsCypress Ridge ..." – dsynkd Dec 11 '13 at 17:32
  • i'm not sure, but maybe that is the answer http://stackoverflow.com/questions/4739715/jqgrid-select-box-in-a-cell – Andrii Horda Dec 11 '13 at 17:45
0

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>darrensadr@gmail.com</cell>
        <cell>8325731944</cell>
        <cell>darrensadr@gmail.com</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>darrenvortex@gmail.com</cell>
        <cell>8326380419</cell>
        <cell>darrenvortex@gmail.com</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

Oleg
  • 220,925
  • 34
  • 403
  • 798