我想在最后一个名为factuur的datarecord上获得一个按钮。我想在那里得到一个div或按钮,但我怎么能在像这样的数据数组中做到这一点。 我在想我应该在td中添加一个类,并用以下内容替换这里的文本:
$('.className').each(function(index, item){
$(item).html(yourButton html);
})
有人知道如何做到这一点或更好的方法吗?I looked into this但是无法弄清楚如何申请是在我的json上。
这就是我的剧本现在的样子:
<table id="oTable" border="1" class="table_tag">
<tr><thead>
<th>Ordernummer</th>
<th>Besteldatum</th>
<th>BTW</th>
<th>Totaalbedrag</th>
<th>Status</th>
<th>Verzonden</th>
<th>Factuur</th>
</thead></tr>
</table>
脚本:
$(function(){
// Basic Setup
var $tableSel = $('#oTable');
$tableSel.dataTable({
'aaData': data,
'aoColumns': [
{'mData': 'EAN'},
{'mData': 'Besteldatum'},
{'mData': 'BTW'},
{'mData': 'Totaalbedrag'},
{'mData': 'Status'},
{'mData': 'Verzonden'},
{'mData': 'Factuur'}
],
'sDom': ''
});
$('#filter').on('click', function(e){
e.preventDefault();
var startDate = $('#start').val(),
endDate = $('#end').val();
filterByDate(1, startDate, endDate);
$tableSel.dataTable().fnDraw();
});
// Clear the filter. Unlike normal filters in Datatables,
// custom filters need to be removed from the afnFiltering array.
$('#clearFilter').on('click', function(e){
e.preventDefault();
$.fn.dataTableExt.afnFiltering.length = 0;
$tableSel.dataTable().fnDraw();
});
});
/* Our main filter function
* We pass the column location, the start date, and the end date
*/
var filterByDate = function(column, startDate, endDate) {
// Custom filter syntax requires pushing the new filter to the global filter array
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var rowDate = normalizeDate(aData[column]),
start = normalizeDate(startDate),
end = normalizeDate(endDate);
// If our date from the row is between the start and end
if (start <= rowDate && rowDate <= end) {
return true;
} else if (rowDate >= start && end === '' && start !== ''){
return true;
} else if (rowDate <= end && start === '' && end !== ''){
return true;
} else {
return false;
}
}
);
};
// converts date strings to a Date object, then normalized into a YYYYMMMDD format (ex: 20131220). Makes comparing dates easier. ex: 20131220 > 20121220
var normalizeDate = function(dateString) {
var date = new Date(dateString);
var normalized = date.getFullYear() + '' + (("0" + (date.getMonth() + 1)).slice(-2)) + '' + ("0" + date.getDate()).slice(-2);
return normalized;
}
var data = [
{
"EAN": "180199",
"Besteldatum": "2003-09-22",
"BTW": "€19,00",
"Totaalbedrag": "€109,00",
"Status": "Verzonden",
"Verzonden": "2003-09-22",
"Factuur": "here"
},
{
"EAN": "180200",
"Besteldatum": "2004-11-12",
"BTW": "€19,00",
"Totaalbedrag": "€109,00",
"Status": "Verzonden",
"Verzonden": "2003-09-22",
"Factuur": "here"
},
];
答案 0 :(得分:0)
每个TR的最后一个孩子的选择器怎么样?
$('tr:last-child').each(()=>{
$(this).append("<button>");
})