I am trying to clone a row which contains select2 tool ,when i clone that row using jQuery the cloned select2 is not responding.In image given below first select2 which is o
I offer to make this, it is my simple example:
function copy_row(id) {
var new_row = $("#"+id+" tbody tr:first").clone();
$("#"+id+" tbody").append(''+new_row.html()+' ');
$("#"+id+" tbody tr:last input").val('');
$("#"+id+" tbody tr:last select").val('');
$("#"+id+" tbody tr:last input[type='checkbox']").prop('checked', false);
// Initialize
$(".select-remote-address:last, .select-remote-address2:last").select2({
language: {
inputTooShort: function() {
return 'Įveskite...';
}},
ajax: {
url: base_url+"index.php/orders/data/getAddress",
type: 'POST',
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, params) {
// parse the results into the format expected by Select2
// since we are using custom formatting functions we do not need to
// alter the remote JSON data, except to indicate that infinite
// scrolling can be used
params.page = params.page || 1;
return {
results: data,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo, // omitted for brevity, see the source of this page
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
});
$(".select-remote-address:last").last().next().next().remove();
$(".select-remote-address2:last").last().next().next().remove();
// Datetimepicker
jQuery('.date_1:last, .date_2:last').datetimepicker({
i18n:{
lt:{
months:[
'Sausis','Vasaris','Kovas','Balandis',
'Gegužė','Birželis','Liepa','Rugpjūtis',
'Rugsėjis','Spalis','Lapkritis','Gruodis',
],
dayOfWeek:[
"Pir", "An", "Tre", "Ket",
"Pen", "Šeš", "Sek",
]
}
},
format:'Y-m-d H:i',
});
}