如何动态添加列和行标题,并根据行和列值如何绑定jqGrid中的数据?

时间:2014-11-18 09:42:51

标签: jqgrid

我需要动态渲染jqGrid。我正在使用WCF Rest服务从CRM数据库获取数据。至于我静态地给列名称和列模型中的列标题将绑定数据。

现在我的要求是Column标题,并且需要动态生成行标题。 根据列和行值,必须显示每个单元格值。 我将数据作为DataTable从服务中发送。 我不知道如何绑定jqGrid中的数据。

请有人提出您的意见。

我从WCF服务

返回的样本DataTable
<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>

这里vc_longtermcondition将是ColumnHeader(哮喘,糖尿病,COPD) 和vc_longtermconditionid将单元格值相应于列标题

MySampleGrid将是这样的

id ----------- Asthma -------------------------ChronicHeartFailure------------------
1.    91c0c30c-816e-e111-a207-005056a50018     dbe68618-816e-e111-a207-005056a50018 

0 个答案:

没有答案