JSQuery: Как добавлять и извлекать атрибуты столбцов?
Я читаю таблицу из базы данных с помощью JQuery и хочу создать атрибут типа данных по столбцу, чтобы выполнять определенные операции по столбцу. На данный момент у меня есть следующее:
var table = $('#maintable').DataTable({
"ajax": {
"type": "GET",
"url": "/cvs/PDFeditor/request/",
"data": function(d) {
d.placeholder = "asdf";
}
},
"columns": [{
"className": 'edit-control',
"orderable": false,
"data": null,
"width": "12px",
"defaultContent": '<button type="button" class="btn btn-sm btn-primary"><span class="glyphicon glyphicon-edit"></span></button>'
}, {
"className": 'delete-control',
"orderable": false,
"data": null,
"width": "12px",
"defaultContent": '<button type="button" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-minus-sign"></span></button>'
}, {
"data": "investor",
"class": 'inv-editable',
"data-type": 'investor'
}, {
"data": "amount",
"type": "num-fmt",
"class": 'inv-editable',
"data-type": 'amount'
}, {
"data": "code",
"class": 'inv-editable',
"data-type": 'code'
}
],
"pageLength": 15,
"order": [ [5, "desc"] ]
});
Моя цель - сохранить атрибут "data-type" в переменной, чтобы обновить столбец в базе данных до:
$('#maintable tbody').on('dblclick', '.inv-editable', function() {
var value = $(this).text();
var data_type = $(this).data("type")
if (data_type == 'investor') {
var input = "<input type = 'text' class = 'input-data' value ='" + value + "' class='form-control' type="investor">";
} else if (data_type == 'amount') {
var input = "<input type = 'text' class = 'input-data' value ='" + value + "' class='form-control' type="amount">";
}
$(this).html(input);
$(this).removeClass("inv-editable")
});
Как я могу получить атрибут data-type из определения таблицы?
Спасибо!