Cleanup styles for editing

This commit is contained in:
Faris Ansari 2017-10-29 17:16:52 +05:30
parent 03f5bb8b59
commit 1b6f749edd
4 changed files with 79 additions and 38 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -259,10 +259,14 @@ export default class DataTable {
'margin-top': (this.header.height() + 1) + 'px' 'margin-top': (this.header.height() + 1) + 'px'
}); });
// hide edit cells by default // center align Sr. No column
this.setStyle('.data-table .body-scrollable .edit-cell', { if (this.options.addSerialNoColumn) {
display: 'none' const index = this.getSerialColumnIndex();
});
this.setStyle(`.data-table [data-col-index="${index}"]`, {
'text-align': 'center'
});
}
this.bodyScrollable.find('.table').css('margin', 0); this.bodyScrollable.find('.table').css('margin', 0);
} }
@ -296,7 +300,6 @@ export default class DataTable {
$(document.body).on('keypress', (e) => { $(document.body).on('keypress', (e) => {
// enter keypress on focused cell // enter keypress on focused cell
if (e.which === 13 && this.$focusedCell && !this.$editingCell) { if (e.which === 13 && this.$focusedCell && !this.$editingCell) {
this.log('editingCell');
this.activateEditing(this.$focusedCell); this.activateEditing(this.$focusedCell);
e.stopImmediatePropagation(); e.stopImmediatePropagation();
} }
@ -313,7 +316,9 @@ export default class DataTable {
$(document.body).on('click', e => { $(document.body).on('click', e => {
if ($(e.target).is('.edit-cell, .edit-cell *')) return; if ($(e.target).is('.edit-cell, .edit-cell *')) return;
self.bodyScrollable.find('.edit-cell').hide(); if (!this.$editingCell) return;
this.$editingCell.removeClass('editing');
this.$editingCell = null; this.$editingCell = null;
}); });
} }
@ -336,6 +341,8 @@ export default class DataTable {
} }
this.$editingCell = $cell; this.$editingCell = $cell;
$cell.addClass('editing');
const $editCell = $cell.find('.edit-cell').empty(); const $editCell = $cell.find('.edit-cell').empty();
const cell = this.getCell(rowIndex, colIndex); const cell = this.getCell(rowIndex, colIndex);
const editing = this.getEditingObject(colIndex, rowIndex, cell.content, $editCell); const editing = this.getEditingObject(colIndex, rowIndex, cell.content, $editCell);
@ -344,7 +351,6 @@ export default class DataTable {
this.currentCellEditing = editing; this.currentCellEditing = editing;
// initialize editing input with cell value // initialize editing input with cell value
editing.initValue(cell.content); editing.initValue(cell.content);
$editCell.show();
} }
} }
@ -677,6 +683,12 @@ export default class DataTable {
return this.datamanager.getRowCount(); return this.datamanager.getRowCount();
} }
getSerialColumnIndex() {
const columns = this.datamanager.getColumns();
return columns.findIndex(column => column.content.includes('Sr. No'));
}
log() { log() {
if (this.options.enableLogs) { if (this.options.enableLogs) {
console.log.apply(console, arguments); console.log.apply(console, arguments);

View File

@ -1,8 +1,13 @@
@import "~bootstrap/scss/functions"; @import "~bootstrap/scss/functions";
@import "~bootstrap/scss/mixins"; @import "~bootstrap/scss/mixins";
@import "~bootstrap/scss/variables"; @import "~bootstrap/scss/variables";
@import "~bootstrap/scss/reboot";
@import "~bootstrap/scss/tables"; @import "~bootstrap/scss/tables";
.data-table * {
outline: none;
}
.data-table { .data-table {
width: 100%; width: 100%;
position: relative; position: relative;
@ -48,16 +53,43 @@
.content { .content {
padding: 8px; padding: 8px;
border: 1px solid transparent; border: 1px solid transparent;
&.ellipsis {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
}
.edit-cell {
display: none;
position: absolute;
padding: 8px;
background: #fff;
z-index: 1;
height: 100%;
input {
outline: none;
width: 100%;
border: none;
height: 1em;
}
} }
&.selected .content { &.selected .content {
border: 1px solid theme-color('primary'); border: 1px solid theme-color('primary');
} }
.content.ellipsis { &.editing {
text-overflow: ellipsis; .content {
white-space: nowrap; display: none;
overflow: hidden; }
.edit-cell {
border: 2px solid theme-color('primary');
display: block;
}
} }
} }
@ -67,24 +99,6 @@
} }
} }
.edit-cell {
position: absolute;
top: -1px;
left: -1px;
background: white;
z-index: 1;
input {
outline: none;
padding: 8px;
font-size: inherit;
font-family: inherit;
width: inherit;
height: inherit;
border: 2px solid theme-color('primary');
}
}
.noselect { .noselect {
-webkit-touch-callout: none; -webkit-touch-callout: none;
-webkit-user-select: none; -webkit-user-select: none;