render: function (data, type, row) {
var switchId = 'customSwitch_' + row.id; // Assuming you have an 'id' field in your data
var switchHTML = '<div class="custom-control custom-switch">';
var isChecked = row.eqas ? 'checked' : ''; // 檢查 rowData.eqas 是否為 true,如果是,則添加 checked 屬性
switchHTML += '<input type="checkbox" class="custom-control-input" id="eqas_' + switchId + '" ' + isChecked + '>';
switchHTML += '<label class="custom-control-label" for="eqas_' + switchId + '">Selected_eqas</label>';
switchHTML += '</div>';
return switchHTML;
},
createdCell: function (td, cellData, rowData, row, col) {
var switchId = 'customSwitch_' + rowData.id; // Assuming you have an 'id' field in your data
var switchElement = $(td).find('#eqas_' + switchId);
console.log("EQAS Element: ", switchElement);
var isChecked = rowData.eqas ? 'checked' : ''; // 根據 rowData.eqas 設置 isChecked 變數
switchElement.change(function () {
console.log("EQAS switchId: ", switchId);
console.log("EQAS isChecked: ", isChecked);
console.log("EQAS switchElement: ", switchElement);
if ($(this).is(':checked')) {
rowData.eqas = true;
rowData.isChanged = true;
} else {
rowData.eqas = false;
rowData.isChanged = true;
}
抓id 的時候ID 要唯一,再還沒標明前,.find('#eqas_' + switchId);
argp 跟eqas table 的row id 資料都混著,要這樣分開才行