私はjqGridが初めてです。コントローラーがモデルの配列データを含む json オブジェクトを返す簡単な例を作成しようとしました。Web ページには、列名を含むグリッドが表示されます。データ自体は表示されません。
ご協力いただきありがとうございます。3日から頑張っています。
これが私のコントローラーです
List<ClientInvoice> clientInvoices = new List<ClientInvoice>
{
new ClientInvoice { Id=1, Name = "test", Note = "note", Amount = 300.00f, Tax = 10.00f, Total = 2111.00f},
new ClientInvoice { Id=2, Name = "test2", Note = "note2", Amount = 300.00f, Tax = 20.00f, Total = 320.00f},
new ClientInvoice { Id=3, Name = "test3", Note = "note3", Amount = 300.00f, Tax = 30.00f, Total = 430.00f},
new ClientInvoice { Id=4, Name = "test", Note = "note", Amount = 300.00f, Tax = 10.00f, Total = 210.00f},
new ClientInvoice { Id=5, Name = "test2", Note = "note2", Amount = 300.00f, Tax = 20.00f, Total = 320.00f},
new ClientInvoice { Id=6, Name = "test3", Note = "note3", Amount = 300.00f, Tax = 30.00f, Total = 430.00f},
new ClientInvoice { Id=7, Name = "test", Note = "note", Amount = 300.00f, Tax = 10.00f, Total = 210.00f},
new ClientInvoice { Id=8, Name = "test2", Note = "note2", Amount = 300.00f, Tax = 21.00f, Total = 320.00f},
new ClientInvoice { Id=9, Name = "test3", Note = "note3", Amount = 400.00f, Tax = 30.00f, Total = 430.00f},
new ClientInvoice { Id=11, Name = "test", Note = "note", Amount = 200.00f, Tax = 10.00f, Total = 210.00f},
new ClientInvoice { Id=12, Name = "test2", Note = "note2", Amount = 300.00f, Tax = 20.00f, Total = 320.00f},
new ClientInvoice { Id=13, Name = "test3", Note = "note3", Amount = 400.00f, Tax = 30.00f, Total = 430.00f},
new ClientInvoice { Id=14, Name = "test", Note = "note", Amount = 200.00f, Tax = 10.00f, Total = 210.00f},
new ClientInvoice { Id=15, Name = "test2", Note = "note2", Amount = 300.00f, Tax = 20.00f, Total = 320.00f},
new ClientInvoice { Id=16, Name = "test3", Note = "note3", Amount = 400.00f, Tax = 30.00f, Total = 430.00f},
new ClientInvoice { Id=17, Name = "test", Note = "note", Amount = 200.00f, Tax = 10.00f, Total = 210.00f},
new ClientInvoice { Id=18, Name = "test2", Note = "note2", Amount = 300.00f, Tax = 20.00f, Total = 320.00f},
new ClientInvoice { Id=19, Name = "test3", Note = "note3", Amount = 400.00f, Tax = 30.00f, Total = 430.00f},
new ClientInvoice { Id=21, Name = "test", Note = "note", Amount = 200.00f, Tax = 10.00f, Total = 210.00f},
new ClientInvoice { Id=22, Name = "test2", Note = "note2", Amount = 300.00f, Tax = 20.00f, Total = 320.00f},
new ClientInvoice { Id=23, Name = "test3", Note = "note3", Amount = 400.00f, Tax = 30.00f, Total = 430.00f},
new ClientInvoice { Id=24, Name = "test", Note = "note", Amount = 200.00f, Tax = 10.00f, Total = 210.00f},
new ClientInvoice { Id=25, Name = "test2", Note = "note2", Amount = 300.00f, Tax = 20.00f, Total = 320.00f},
new ClientInvoice { Id=26, Name = "test3", Note = "note3", Amount = 400.00f, Tax = 30.00f, Total = 430.00f},
new ClientInvoice { Id=27, Name = "test", Note = "note", Amount = 200.00f, Tax = 10.00f, Total = 210.00f},
new ClientInvoice { Id=28, Name = "test2", Note = "note2", Amount = 300.00f, Tax = 20.00f, Total = 320.00f},
new ClientInvoice { Id=29, Name = "test3", Note = "note3", Amount = 400.00f, Tax = 30.00f, Total = 430.00f},
};
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
//use Serialize method to convert patient list to json string
string clientInvoiceJson = serializer.Serialize(clientInvoices);
ViewBag.ClientInvoicesJson = clientInvoiceJson;
そして景色はこんな感じ
<input type="hidden" id="clientInvoices" value="@ViewBag.ClientInvoicesJson" />
<table id="list47"></table>
<div id="plist47"></div>
<script type="text/javascript">
var mydata1 = $("#clientInvoices").attr("value");
var mydata = mydata1;
jQuery("#list47").jqGrid({
data: mydata,
datatype: 'json',
height: 150,
rowNum: 10,
rowList: [10, 20, 30],
colNames: ['Inv No', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
colModel: [
{ name: 'Id', index: 'Id', width: 60 },
{ name: 'Name', index: 'Name', width: 100 },
{ name: 'Amount', index: 'Amount', width: 80 },
{ name: 'Tax', index: 'Tax', width: 80 },
{ name: 'Total', index: 'Total', width: 80 },
{ name: 'Note', index: 'Note', width: 150 }
],
pager: "#plist47",
viewrecords: true,
caption: "Manipulating Array Data"
});
</script>