如何从datatable-javascript-MVC获取信息
我创建了一个ASP.net MVC应用程序,并创建了一个DataTable[DataTable.net],如下所示:如何从datatable-javascript-MVC获取信息,javascript,c#,asp.net,asp.net-mvc,datatables,Javascript,C#,Asp.net,Asp.net Mvc,Datatables,我创建了一个ASP.net MVC应用程序,并创建了一个DataTable[DataTable.net],如下所示: <table id="invoiceTable"> <thead> <tr> <th>Invoice ID</th> <th>Date</th> <th>Reciept Date</t
<table id="invoiceTable">
<thead>
<tr>
<th>Invoice ID</th>
<th>Date</th>
<th>Reciept Date</th>
<th>Category</th>
<th>Total Value</th>
<th>Invoice Ref</th>
<th>Client</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@{
foreach (FreeAgentApp.Models.CustomInvoice _invoice in ViewBag.Invoices)
{
<tr>
<td>@_invoice.InvoiceId</td>
<td>@_invoice.Date</td>
<td>@_invoice.RecpDate</td>
<td>@_invoice.Category</td>
<td>@_invoice.TotalValue</td>
<td>@_invoice.InvoiceRef</td>
<td>@_invoice.Client</td>
<td>@_invoice.Status</td>
</tr>
}
}
</tbody>
</table>
// Row data
$(document).ready(function () {
oTable = $('#invoiceTable').dataTable();
oTable.$('tr').click(function () {
var data = oTable.fnGetData(this);
alert(data);
// ... do something with the array / object of data for the row
});
});
"000,26-01-14,27-01-14,001,1000,inv,something ltd,paid"
变量数据将提供行中每个值的字符串,用逗号分隔,如下所示:
<table id="invoiceTable">
<thead>
<tr>
<th>Invoice ID</th>
<th>Date</th>
<th>Reciept Date</th>
<th>Category</th>
<th>Total Value</th>
<th>Invoice Ref</th>
<th>Client</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@{
foreach (FreeAgentApp.Models.CustomInvoice _invoice in ViewBag.Invoices)
{
<tr>
<td>@_invoice.InvoiceId</td>
<td>@_invoice.Date</td>
<td>@_invoice.RecpDate</td>
<td>@_invoice.Category</td>
<td>@_invoice.TotalValue</td>
<td>@_invoice.InvoiceRef</td>
<td>@_invoice.Client</td>
<td>@_invoice.Status</td>
</tr>
}
}
</tbody>
</table>
// Row data
$(document).ready(function () {
oTable = $('#invoiceTable').dataTable();
oTable.$('tr').click(function () {
var data = oTable.fnGetData(this);
alert(data);
// ... do something with the array / object of data for the row
});
});
"000,26-01-14,27-01-14,001,1000,inv,something ltd,paid"
我想把所有这些值分开。注意这可以通过在逗号上拆分来完成,但是表中的值可以包含逗号
如何分离此字符串?根据DataTables文档
oTable.fnGetData(this)代码>返回一个填充了行中定义数据的数组,这样您就可以直接从数据中访问数据
var invoiceId = data[0];
var date = data[1];
var recpDate = data[2];
// etc. etc.
我说过我不想在逗号上分开。如果表中的数据包含逗号怎么办?是的,它的datatables.net-除非值中有逗号,否则您的答案是正确的,例如“00,00”可以是值