我想使用jQuery DataTables將數據綁定到表。如何使用jQuery DataTables綁定表中的JSON數據
我使用操作結果返回數據並將其轉換爲JSON,數據不顯示在表中,只顯示空白列。
這裏是視圖部分
@model Guardian.Core.Model.Models.PatientMedicationsCollection
@{
var ModelJsonData = Newtonsoft.Json.JsonConvert.SerializeObject(Model);
Layout = null;
}
<script type="text/javascript">
var MedicationMasterData = JSON.parse(@Html.Raw(Json.Encode(ModelJsonData)));
var CCDAChecked;
var LatestCCDA;
var AllCCDA;
var CLaimsChecked;
var AllClaims;
var Last6Month;
var OneYear;
var FilteredData = [];
$(document).ready(function() {
debugger;
$.each(MedicationMasterData, function (idx, obj) {
FilteredData.push(this);
});
FilterTable(MedicationMasterData);
});
function FilterTable(FilteredData) {
debugger;
FData = JSON.stringify(FilteredData)
$('#PatientMedications').DataTable({
"scrollX": 100,
"paging": true,
"pagingType": "full_numbers",
"dom": '<"toolbar">frtip',
"aaData": FData,
columns: [
{ title: "PatientID" },
{ title: "FirstName" },
{ title: "LastName" },
{ title: "DOB." },
{ title: "Gender" },
{ title: "Source" },
{ title: "SourceCreatedDate" },
{ title: "SourceKeyID" },
{ title: "LatestCCDA" },
{ title: "Code" },
{ title: "CodeType" },
{ title: "DrugName" },
{ title: "DrugDecriptionsM" },
{ title: "StartDate" },
{ title: "StopDate" },
{ title: "Instructions" },
{ title: "Status" },
{ title: "DoseQuantity" },
{ title: "RateQuantity" },
{ title: "RateQuantityUnit" },
{ title: "DrugDecriptionsM" },
{ title: "ClaimLineFromDate" },
{ title: "DaysSupply" },
{ title: "DOSAGEFORMNAME" },
{ title: "ROUTENAME" },
{ title: "ST" }
]
});
的Controler部分,我們使用的是行動的結果
public ActionResult PatientMedications(int patientID)
{
return PartialView(patientrepository.PatientMedications(patientID));
}
幾個問題 - 你爲什麼要返回 'PartialView'?你爲什麼不返回一個json對象,而不是做所有的客戶端處理?使用'return Json(new {aaData =' – markpsmith
我沒有清楚地理解你的問題,但我想你的列名應該匹配,然後它會顯示data – Hiba