Created
November 28, 2024 12:41
-
-
Save MikeTatsky/c73920569d074f548c2722363dd649c7 to your computer and use it in GitHub Desktop.
FancyGrid disable checkbox in select
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
document.addEventListener('DOMContentLoaded', ()=> { | |
const GRID_COLUMN_CLS = Fancy.GRID_COLUMN_CLS; | |
const GRID_CELL_CLS = Fancy.GRID_CELL_CLS; | |
const GRID_CELL_INNER_CLS = Fancy.GRID_CELL_INNER_CLS; | |
const T_CELL_PLUS_INNER = `.${GRID_CELL_CLS} .${GRID_CELL_INNER_CLS}`; | |
Fancy.grid.Body.prototype.renderSelect = function (i, rowIndex, complex) { | |
let checkBox; | |
var me = this, | |
w = me.widget, | |
s = w.store, | |
columns = me.getColumns(), | |
column = columns[i], | |
columnsDom = me.el.select(`.${GRID_COLUMN_CLS}`), | |
columnDom = columnsDom.item(i), | |
cellsDomInner = columnDom.select(T_CELL_PLUS_INNER), | |
j, | |
jL; | |
if (rowIndex !== undefined) { | |
j = rowIndex; | |
jL = rowIndex + 1; | |
} else { | |
j = 0; | |
jL = s.getLength(); | |
} | |
if (w.infinite) { | |
const numOfVisibleCells = w.getNumOfVisibleCells(); | |
if (jL > numOfVisibleCells) { | |
jL = numOfVisibleCells; | |
} | |
} | |
for (; j < jL; j++) { | |
var item, | |
value = false, | |
id = s.get(j, 'id'), | |
cellInnerEl = cellsDomInner.item(j); | |
checkBox = cellInnerEl.select('.fancy-field-checkbox'); | |
var checkBoxId, | |
isCheckBoxInside = checkBox.length !== 0, | |
editable = true; | |
if (w.selection.memory) { | |
if (w.selection.memory.all && !w.selection.memory.excepted[id]) { | |
value = true; | |
w.selection.domSelectRow(j); | |
} else if (w.selection.memory.has(id)) { | |
value = true; | |
w.selection.domSelectRow(j); | |
} else { | |
value = false; | |
w.selection.domDeSelectRow(j); | |
} | |
if (s.isTree) { | |
item = s.getItem(j); | |
var $selected = item.get('$selected'); | |
if ($selected) { | |
const recurseSelect = function (childs) { | |
F.each(childs, function (child) { | |
if (!child.fields) { | |
return; | |
} | |
if (child.get('$selected') === false) { | |
w.selection.memory.remove(child.id); | |
return; | |
} | |
item.set('$selected', undefined); | |
child.set('$selected', true); | |
w.selection.memory.add(child.id); | |
if (child.data.child && child.data.child[0] && child.data.child[0].fields) { | |
recurseSelect(child.data.child); | |
} | |
}); | |
}; | |
recurseSelect(item.data.child); | |
} | |
} | |
} else { | |
if (cellInnerEl.parent().hasClass(GRID_CELL_SELECTED_CLS)) { | |
value = true; | |
} | |
} | |
if (column.type !== 'select' && !column.select) { | |
continue; | |
} | |
if (w.selection.disabled) { | |
editable = false; | |
} | |
if (isCheckBoxInside === false) { | |
let renderTo = cellsDomInner.item(j); | |
if (complex) { | |
renderTo = renderTo.select('.fancy-grid-cell-inner-select').item(0).dom; | |
if (!Fancy.isBoolean(value)) { | |
value = false; | |
} | |
} else { | |
cellsDomInner.item(j).update(''); | |
renderTo = renderTo.dom; | |
} | |
const checkBoxConfig = { | |
renderTo: renderTo, | |
renderId: true, | |
value: value, | |
label: false, | |
stopIfCTRL: true, | |
editable: editable, | |
disabled: !editable, | |
style: { | |
padding: '0px', | |
display: 'inline-block' | |
}, | |
events: [{ | |
beforechange: function (field) { | |
if (w.selection.stopOneTick) { | |
field.canceledChange = true; | |
} | |
} | |
}] | |
}; | |
checkBox = new Fancy.CheckBox(checkBoxConfig); | |
if (s.isTree && w.selection.memory) { | |
if (w.selection.memory.tree.selected[id] && !w.selection.memory.tree.allSelected[id] && item) { | |
const child = item.get('child'); | |
if (child && child.length) { | |
checkBox.setMiddle(true); | |
} | |
} | |
} | |
} else { | |
checkBoxId = checkBox.dom.id; | |
checkBox = Fancy.getWidget(checkBoxId); | |
checkBox.set(value, false); | |
} | |
if (column.processCell) { | |
var o = { | |
rowIndex: j, | |
column: column, | |
id: id, | |
data: s.get(j), | |
item: s.getItem(j), | |
value, | |
widget: checkBox | |
}; | |
column.processCell(o); | |
} | |
} | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment