delCell
The delCell
method lets you remove a single Cell
from a Row
.
delCell(
tableId: string,
rowId: string,
cellId: string,
forceDel?: boolean,
): this
Type | Description | |
---|---|---|
tableId | string | |
rowId | string | |
cellId | string | |
forceDel? | boolean | An optional flag to indicate that the whole |
returns | this | A reference to the |
When there is no TablesSchema
applied to the Store
, then if this is the last Cell
in its Row
, then that Row
will be removed. If, in turn, that is the last Row
in its Table
, then that Table
will be removed.
If there is a TablesSchema
applied to the Store
and it specifies a default value for this Cell
, then deletion will result in it being set back to its default value. To override this, use the forceDel
parameter, as described below.
The forceDel
parameter is an optional flag that is only relevant if a TablesSchema
provides a default value for this Cell
. Under such circumstances, deleting a Cell
value will normally restore it to the default value. If this flag is set to true
, the complete removal of the Cell
is instead guaranteed. But since doing do so would result in an invalid Row
(according to the TablesSchema
), in fact the whole Row
is deleted to retain the integrity of the Table
. Therefore, this flag should be used with caution.
Examples
This example removes a Cell
from a Row
without a TablesSchema
.
import {createStore} from 'tinybase';
const store = createStore().setTables({
pets: {fido: {species: 'dog', sold: true}},
});
store.delCell('pets', 'fido', 'sold');
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog'}}}
This example removes a Cell
from a Row
with a TablesSchema
that defaults its value.
import {createStore} from 'tinybase';
const store = createStore()
.setTables({
pets: {fido: {species: 'dog', sold: true}},
})
.setTablesSchema({
pets: {
species: {type: 'string'},
sold: {type: 'boolean', default: false},
},
});
store.delCell('pets', 'fido', 'sold');
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog', sold: false}}}
This example removes a Cell
from a Row
with a TablesSchema
that defaults its value, but uses the forceDel
parameter to override it.
import {createStore} from 'tinybase';
const store = createStore()
.setTables({
pets: {fido: {species: 'dog', sold: true}, felix: {species: 'cat'}},
})
.setTablesSchema({
pets: {
species: {type: 'string'},
sold: {type: 'boolean', default: false},
},
});
store.delCell('pets', 'fido', 'sold', true);
console.log(store.getTables());
// -> {pets: {felix: {species: 'cat', sold: false}}}
Since
v1.0.0