我尝试追加行,然后select2不能正常工作,因为跨度类select2-container-默认每次添加新行都会加倍,并且我无法选择选项值,有人可以帮忙吗?
<script type="text/javascript">
$(document).ready(function(){
//add row
$('#addRow').on('click',function(){
var lastRow = $('#dataTable tbody tr:last').html();
$('#dataTable tbody').append('<tr>' + lastRow + '</tr>');
$('#dataTable tbody tr:last input').val('');
$('.select2:last').select2({
placeholder : "-Pilih Product-",
ajax:{
type : "GET",
url : "<?php echo site_url('quotation/get_product')?>",
delay : 250,
dataType : "json",
data : function(params){
return{
name : params.term
}
},
processResults : function(data,page){
var results = [0];
$.each(data,function(index,items){
results.push({
id:items.item_code,
text:items.item_name,
});
});
return {
results:results
};
},
}
});
$('[data-toggle="tooltip"].form-control').tooltip();
$('.prize').autoNumeric();
});
// Delete selected checkbox in the table
$('#delRow').click(function() {
var lenRow = $('#dataTable tbody tr').length;
var lenChecked = $("#dataTable input[type='checkbox']:checked").length;
var row = $("#dataTable tbody input[type='checkbox']:checked").parent().parent();
if (lenRow == 1 || lenRow <= 1 || lenChecked >= lenRow) {
alert("Can't remove all row!");
} else {
row.remove();
}
});
});