私はjQueryを利用するページに取り組んでおり、jqGridもページに組み込む予定です。ページには、テーブルに行を書き込む送信ボタンがあり、onReadyStateChange が発生すると、コールバック関数が開始されます。その関数内で、jqGrid が再ロード/置換されます。現在のコードは次のとおりです。
var myReq = new XMLHttpRequest();
var myURL = myServer + myOtherInfo;
..... (other parameters are added to the myURL variable)
myReq.open("GET",myURL, true); // true=asynchronous, false=synchronous
myReq.onreadystatechange = mycallback;
myReq.send(null);
function mycallback() {
var data = myReq.responseText;
var xdata = myReq.responseXML;
データセットは非常に小さいため、ページ上のグリッドを単純に再作成/置換することにしました。上記の 2 つの変数 (data と xdata) にデータが戻されていることはわかっています。現時点では、ResponseText と ResponseXML (可変行数) で 1 つのフィールドのみを渡しています。最終的には 3 ~ 5 フィールドになります。
data/myReq.responseText
またはxdata/myReq.responseXML
変数/オブジェクトに既にあるものをjqGridに使用させるにはどうすればよいですか?
datastr
& datatype
ofを使用すると思っていxmlstring
ましたが、思ったように機能しません。jqGrid の一部を以下に示します。これは、 にも含まれていmycallback function
ます。
$("#myGrid").jqGrid({
xmlReader: {
datastr: xdata,
datatype: "xmlstring",
root: "Row",
row: "ContactName",
colNames: ["Contact Name"],
colModel: [{name:"ContactName",index:"ContactName",width:200,align:"right"}],
viewrecords: true,
caption: "My Grid"
}
});
私はjQueryとjqGridの両方に非常に慣れていないため、支援や指示をいただければ幸いです。
編集
以下は、私が現在使用しているデータのサンプルです (Northwind データベースから)。
<?xml version="1.0" encoding="UTF-8" ?>
<Rowsets DateCreated="2013-05-02T09:18:07" EndDate="2013-05-02T09:18:07" StartDate="2013-05-02T08:18:07" Version="12.0.6 Build(13)">
<Rowset>
<Columns>
<Column Description="ContactName" MaxRange="1" MinRange="0" Name="ContactName" SQLDataType="12" SourceColumn="ContactName" />
<Column Description="City" MaxRange="1" MinRange="0" Name="City" SQLDataType="12" SourceColumn="City" />
<Column Description="Country" MaxRange="1" MinRange="0" Name="Country" SQLDataType="12" SourceColumn="Country" />
</Columns>
<Row>
<ContactName>Maria Anders</ContactName>
<City>Berlin</City>
<Country>Germany</Country>
</Row>
<Row>
<ContactName>Ana Trujillo</ContactName>
<City>México D.F.</City>
<Country>Mexico</Country>
</Row>
<Row>
<ContactName>Antonio Moreno</ContactName>
<City>México D.F.</City>
<Country>Mexico</Country>
</Row>
<Row>
<ContactName>Thomas Hardy</ContactName>
<City>London</City>
<Country>UK</Country>
</Row>
<Row>
<ContactName>Christina Berglund</ContactName>
<City>Luleå</City>
<Country>Sweden</Country>
</Row>
<Row>
<ContactName>Hanna Moos</ContactName>
<City>Mannheim</City>
<Country>Germany</Country>
</Row>
</Rowset>
</Rowsets>
最初の投稿以来、データがグリッドに表示されるようになり、現在、その書式設定を試しています。
最終的には、グリッドの各行に送信ボタンを追加して、ユーザーが行を選択し、送信ボタンをクリックしてその行をテーブルに再度追加できるようにしたいと考えています (それが完了したら、使用します列の 1 つとして日時スタンプ)。
当初、私は XMLHttpRequest を使用してクエリを実行し、XML を受信し、onreadystatechange を使用して、グリッドを読み込んで表示するコールバック関数を開始していました。