效果图:
Jtable的子表用法:
_$masterTable.jtable({ title: app.localize('PharmacyInventory'), openChildAsAccordion: true, paging: true, actions: { listAction: { method: _masterService.getItems } }, fields: { id: { key: true, list: false }, //... details: { title: '', '3%', sorting: false, edit: false, create: false, display: function (data) { var master = data.record; var $span = $('<span></span>'); var $btnView = $('<button class="btn btn-default btn-xs" title="' + app.localize('Details') + '"><i class="fa fa-align-justify"></i></button>') .appendTo($span) .click(function () { $('#MasterTable').jtable('openChildTable', $btnView.closest('tr'), { title: master.medicineName + "(" + master.pinYin + ")", actions: { listAction: { method: _masterService.getSubItems } }, fields: { productionDate: { title: app.localize('ProductionDate'), '10%', display: function (data) { var $span = $('<span></span>'); $span.append(moment(data.record.productionDate).format('YYYY-MM-DD')+ " "); return $span; } }, period: { title: app.localize('Period'), '10%' }, effectiveDate: { title: app.localize('EffectiveDate'), '15%', display: function (data) { var $span = $('<span></span>'); $span.append('<label class="font-red bold">' + moment(data.record.effectiveDate).format('YYYY-MM-DD') + "</label> "); return $span; } }, batchNo: { title: app.localize('BatchNo'), '10%', display: function (data) { var $span = $('<span></span>'); $span.append(data.record.batchNo + " "); return $span; } }, stockBalance: { title: app.localize('PharmacyInventory'), '10%', display: function (data) { var $span = $('<span></span>'); $span.append('<label class="font-red bold">' + data.record.stockBalance + "</label> "); return $span; } } } }, function (data) { data.childTable.jtable('load', { sourceId: master.medicineID }); }); }); return $span; } }, medicineName: { title: app.localize('MedicineName'), '15%', display: function (data) { var $span = $('<span></span>'); $span.append(data.record.medicineName + "(" + data.record.pinYin + ")" + " "); return $span; } }, category: { title: app.localize('Category'), '10%', display: function (data) { var $span = $('<span></span>'); $span.append(data.record.categoryText + " "); return $span; } }, dosage: { title: app.localize('Dosage'), '7%', display: function (data) { var $span = $('<span></span>'); $span.append(data.record.dosageText + " "); return $span; } }, spec: { title: app.localize('Spec'), '7%', display: function (data) { var $span = $('<span></span>'); $span.append(data.record.specText + " "); return $span; } }, minPacking: { title: app.localize('MinPacking'), '7%', display: function (data) { var $span = $('<span></span>'); $span.append(data.record.minPackingText + " "); return $span; } }, unit: { title: app.localize('Unit'), '7%', display: function (data) { var $span = $('<span></span>'); $span.append(data.record.unitText + " "); return $span; } }, limitation: { title: app.localize('Limitation'), '7%', display: function (data) { var $span = $('<span></span>'); $span.append(data.record.limitation + " "); return $span; } }, usage: { title: app.localize('Usage'), '7%', display: function (data) { var $span = $('<span></span>'); $span.append(data.record.usageText + " "); return $span; } }, route: { title: app.localize('Route'), '7%', display: function (data) { var $span = $('<span></span>'); $span.append(data.record.routeText + " "); return $span; } }, stockBalance: { title: app.localize('PharmacyInventory'), '10%', display: function (data) { var $span = $('<span></span>'); $span.append('<label class="font-red bold">' + data.record.stockBalance + "</label> "); return $span; } } } });
参考链接:http://www.codeproject.com/Articles/277576/AJAX-based-CRUD-tables-using-ASP-NET-MVC-and-jTa