The first hit that I got for an editable grid is:
https://www.npmjs.com/package/editable-grid
The examples are at https://www.npmjs.com/package/editable-grid#view-demos-with-implementation-code.
In particular the example Editable cells is the one, that I think you need.
The code for an editable table according to the example would be as follows. In order to have the data persist to database you would need to add a button that on click, sends the data of the editable table.
function (el) {
var grid = new Grid({
el: el,
stateManager: {
isEditable: function (rowId, colId) {
if (colId === 'readOnly') { return false; }
return true;
}
},
columns: [
{ id: 'readOnly', title: 'Title', width: '20%' },
{ id: 'string', title: 'String', width: '20%' },
{ id: 'cost', title: 'Cost', width: '20%', type: 'cost' },
{ id: 'percent', title: 'Percent', width: '20%', type: 'percent' },
{ id: 'date', title: 'Date', width: '20%', type: 'date' }
],
data: [
{ id: 'id-1', readOnly: 'Non editable field', string: 'Hello World', cost: 1000.23, percent: 0.45, date: '2014-03-27' },
{ id: 'id-2', readOnly: 'Non editable field', string: 'Good Morning', percent: 0.45 },
{ id: 'id-3', readOnly: 'Non editable field', cost: 1000.23, percent: 0.45, date: '2014-04-27' }
]
});
grid.render();
grid.on('editable-value-updated', function (/*obj*/) {
});
}
You can likely get the current values of the cells by using the grid variables. If that is not possible, then you can listen to the events like
grid.on('editable-value-updated', function(params) {});
grid.on('editable-new-row-value-changed', function(newObj, colId) {});
grid.on('editable-new-row', function(newObj) {});
to get the changes to data and store those in a temporary object.
P.S. Note that you don't need to do npm install to get the library, you can use the standalone versions.
- http://skinnybrit51.com/editable-grid/dist/editable_grid.min.js
- http://skinnybrit51.com/editable-grid/dist/editable_grid.min.css
Both the js and css files are required.