0

I need to dynamically render the jqGrid. I am using WCF Rest service to get the Data from the CRM Database. As far as i have statically gave the Column header in column name and column model will bind the data.

Now my requirement is Column header and Row Header needs to be generated dynamically. Based on the column and row value each cell value has to be shown. I am sending the data as DataTable from the service. I am not sure how to bind the data in jqGrid.

Please anyone give your input.

My sample DataTable which is returned from WCF Service

<DataTable xmlns="http://schemas.datacontract.org/2004/07/System.Data">
  <xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="LTC" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="LTC">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="vc_longtermcondition" type="xs:string" minOccurs="0"/>
                <xs:element name="vc_longtermconditionid" type="xs:string" minOccurs="0"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <DocumentElement xmlns="">
      <LTC diffgr:id="LTC1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
        <vc_longtermcondition>Asthma</vc_longtermcondition>
        <vc_longtermconditionid>91c0c30c-816e-e111-a207-005056a50018</vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC2" msdata:rowOrder="1" diffgr:hasChanges="inserted">
        <vc_longtermcondition>Chronic Heart Failure</vc_longtermcondition>
        <vc_longtermconditionid>dbe68618-816e-e111-a207-005056a50018</vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC3" msdata:rowOrder="2" diffgr:hasChanges="inserted">
        <vc_longtermcondition>CKD</vc_longtermcondition>
        <vc_longtermconditionid>
          dde68618-816e-e111-a207-005056a50018
        </vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC4" msdata:rowOrder="3" diffgr:hasChanges="inserted">
        <vc_longtermcondition>
          COPD
        </vc_longtermcondition>
        <vc_longtermconditionid>
          e94f4222-816e-e111-a207-005056a50018
        </vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC5" msdata:rowOrder="4" diffgr:hasChanges="inserted">
        <vc_longtermcondition>
          Diabetes Type 1
        </vc_longtermcondition>
        <vc_longtermconditionid>
          e1b54c29-816e-e111-a207-005056a50018
        </vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC6" msdata:rowOrder="5" diffgr:hasChanges="inserted">
        <vc_longtermcondition>
          Diabetes Type 2
        </vc_longtermcondition>
        <vc_longtermconditionid>
          2b86ad32-816e-e111-a207-005056a50018
        </vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC7" msdata:rowOrder="6" diffgr:hasChanges="inserted">
        <vc_longtermcondition>
          Hypertension
        </vc_longtermcondition>
        <vc_longtermconditionid>
          d1d7c339-816e-e111-a207-005056a50018
        </vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC8" msdata:rowOrder="7" diffgr:hasChanges="inserted">
        <vc_longtermcondition>
          LTC10
        </vc_longtermcondition>
        <vc_longtermconditionid>
          df1dbcd1-c977-e111-ac35-005056a50018
        </vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC9" msdata:rowOrder="8" diffgr:hasChanges="inserted">
        <vc_longtermcondition>
          LTC11
        </vc_longtermcondition>
        <vc_longtermconditionid>
          40f5deda-c977-e111-ac35-005056a50018
        </vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC10" msdata:rowOrder="9" diffgr:hasChanges="inserted">
        <vc_longtermcondition>
          LTC12
        </vc_longtermcondition>
        <vc_longtermconditionid>
          42f5deda-c977-e111-ac35-005056a50018
        </vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC11" msdata:rowOrder="10" diffgr:hasChanges="inserted">
        <vc_longtermcondition>
          LTC8
        </vc_longtermcondition>
        <vc_longtermconditionid>
          fe5e3ecb-c977-e111-ac35-005056a50018
        </vc_longtermconditionid>
      </LTC>
      <LTC diffgr:id="LTC12" msdata:rowOrder="11" diffgr:hasChanges="inserted">
        <vc_longtermcondition>
          LTC9
        </vc_longtermcondition>
        <vc_longtermconditionid>
          005f3ecb-c977-e111-ac35-005056a50018
        </vc_longtermconditionid>
      </LTC>
    </DocumentElement>
  </diffgr:diffgram>
</DataTable>

Here vc_longtermcondition will be the ColumnHeader(Asthma,Diabetes,COPD) and vc_longtermconditionid will the cell value respective to the columnheader

MySampleGrid will be like this

id ----------- Asthma -------------------------ChronicHeartFailure------------------
1.    91c0c30c-816e-e111-a207-005056a50018     dbe68618-816e-e111-a207-005056a50018 
Oleg
  • 220,925
  • 34
  • 403
  • 798
Swathi
  • 1
  • 2
  • You should append the text of your question with an example of JSON data (at least two rows of data) returned from WCF service. The description "I am sending the data as DataTable" isn't clear enough. – Oleg Nov 18 '14 at 09:54
  • By the way you can use Developer Tools of Internet Explorer/Chrome/Firefox (press F12 to start) or free tools like [Fiddler](http://www.telerik.com/fiddler) to trace the HTTP traffic. – Oleg Nov 18 '14 at 10:18
  • You are welcome! You should click "edit" link (button) below your question and *modify the text*. You should append the text with exact JSON data example. jqGrid is unable to read any common JSON data and to display it as a grid, but one can specify `jsonReader` parameter and `colModel` so that the data will be read (see [the documentation](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data)). So you should first post the exact JSON data and then one can help you. – Oleg Nov 21 '14 at 06:03
  • Hi Oleg.I have updated my question. – Swathi Nov 21 '14 at 06:06
  • Web browsers don't contains common XML parser. You should convert the output data to JSON instead of XML. One can use the standard `System.ServiceModel.Web` (see [here](http://stackoverflow.com/a/3914796/315935)) or to use any other JSON serializer (see [here](http://stackoverflow.com/a/3079326/315935) and [here](http://stackoverflow.com/a/3131413/315935)). – Oleg Nov 21 '14 at 06:17

0 Answers0