Tabulator 4.2 - how to use a multi element cell for editingRetrieve the position (X,Y) of an HTML elementHow do I detect a click outside an element?How do I check if an element is hidden in jQuery?How to Check if element is visible after scrolling?How do I find out which DOM element has the focus?How do I add a class to a given element?How can I select an element with multiple classes in jQuery?How can I select an element by name with jQuery?How to move an element into another element?How do I remove a particular element from an array in JavaScript?How can I add new array elements at the beginning of an array in Javascript?
Why do motor drives have multiple bus capacitors of small value capacitance instead of a single bus capacitor of large value?
A vector is defined to have a magnitude and *a* direction, but the zero vector has no *single* direction. So, how is the zero vector a vector?
Why do presidential pardons exist in a country having a clear separation of powers?
Understanding data transmission rates over copper wire
The correct way of compute indicator function in Mathematica
My colleague treats me like he's my boss, yet we're on the same level
IList<T> implementation
Moscow SVO airport, how to avoid scam taxis without pre-booking?
Don't look at what I did there
Turn off Google Chrome's Notification for "Flash Player will no longer be supported after December 2020."
Is there anything in the universe that cannot be compressed?
How to investigate an unknown 1.5GB file named "sudo" in my Linux home directory?
Does using composite keys violate 2NF
How can I portray a character with no fear of death, without them sounding utterly bored?
What caused the end of cybernetic implants?
What is the chance of getting a Red Cabbage in year 1?
When you have to wait for a short time
Why haven't the British protested Brexit as ardently as the Hong Kong protesters?
Calculate Landau's function
apt-file regex: find multiple packages at once using or
What's the origin of the concept of alternate dimensions/realities?
Resources to learn about firearms?
Divide Numbers by 0
Does the Freedom of Movement spell prevent petrification by the Flesh to Stone spell?
Tabulator 4.2 - how to use a multi element cell for editing
Retrieve the position (X,Y) of an HTML elementHow do I detect a click outside an element?How do I check if an element is hidden in jQuery?How to Check if element is visible after scrolling?How do I find out which DOM element has the focus?How do I add a class to a given element?How can I select an element with multiple classes in jQuery?How can I select an element by name with jQuery?How to move an element into another element?How do I remove a particular element from an array in JavaScript?How can I add new array elements at the beginning of an array in Javascript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to edit a cell with an input and a dropdown.
The goal being to edit, in this case, a disk size.
I would therefore need to combine , editor:"input", editor:true, validator:["min:0", "max:999", "numeric"]}
with , editor:"select", editorParams:"MB":"MB", "TB":"TB", "GB":"GB"
The final result being something like 146GB.
1st try:
Since this looks like a custom editor, I wrote this:
var CapacityEditor = function(cell, onRendered, success, cancel, editorParams)
var capacity = document.createElement("div");
capacity.style.width = "100%";
var size = document.createElement("input");
size.setAttribute("type", "text");
size.style.width = "50px";
size.style.textAlign = "right";
onRendered(function()
size.focus();
//size.style.css = "100%";
);
capacity.append(size);
var multiplier = document.createElement("select");
multiplier.style.width = "45px";
multiplier.append(new Option("MB","MB",true,true));
multiplier.append(new Option("GB","GB"));
multiplier.append(new Option("TB","TB"));
capacity.append(multiplier);
var multi = "MB";
function successFunc()
success(size.value+multi);
function setmultiFunc()
multi = multiplier.options[multiplier.selectedIndex].text;
successFunc();
size.addEventListener("change", successFunc);
size.addEventListener("blur", successFunc);
multiplier.addEventListener("change", successFunc);
multiplier.addEventListener("blur", successFunc);
return capacity;
with:
title:"Capacity", field:"Size", align:"center", width:95, editor:CapacityEditor, sorter:SizeSorter, sortable: true,
So, on that one, there are 'a few' issues.
- I have no idea what the success() is supposed to do
- I'm returning a div hoping that the content would populate the cell
- Whenever I put in a value and make a selection, it does not get saved at all; probably because I'm returning a div in the first place
2nd try: Since the edit does not work, maybe I could use the cell click event instead...
The cell.getElement()
does give me the DIV content for the cell as expected but there is no such thing as a cell.setElement()
, right?
I can create my own div, like in the first try and then use the cell.setValue()
to well, set the value but if I can't display my div in the first place, that doesn't work too good.
Tried cell.getElement().innerHTML = "<div>...</div>"
but nothing (waaaay too easy)
3rd try: Well, let's thing outside the box then (literally)
In other words, lets create a very simple modal, display it on top of the existing cell and then use, again, cell.setValue()
to update the value.
Problem is: how do I get the position of the cell?
Using the built-in editor, the editor:"select"
replaces the cell's div with an input in readonly and created a div in the document body with multiple div and then positions it right below the cell making it look like a dropdown:
<input type="text" readonly="" style="padding: 4px; width: 100%; box-sizing: border-box; height: 100%;">
<div class="tabulator-edit-select-list" style="min-width: 80px; top: 348px; left: 671px;"><div class="tabulator-edit-select-list-item" tabindex="0">10K</div><div class="tabulator-edit-select-list-item" tabindex="0">15K</div><div class="tabulator-edit-select-list-item" tabindex="0">7.2K</div><div class="tabulator-edit-select-list-item active" tabindex="0">na</div></div>
Note the top
and left
style attributes.
Oli is able to do it so there has to be a way, right?
Any help, advise, fix would be much appreciated.
javascript tabulator
add a comment |
I'm trying to edit a cell with an input and a dropdown.
The goal being to edit, in this case, a disk size.
I would therefore need to combine , editor:"input", editor:true, validator:["min:0", "max:999", "numeric"]}
with , editor:"select", editorParams:"MB":"MB", "TB":"TB", "GB":"GB"
The final result being something like 146GB.
1st try:
Since this looks like a custom editor, I wrote this:
var CapacityEditor = function(cell, onRendered, success, cancel, editorParams)
var capacity = document.createElement("div");
capacity.style.width = "100%";
var size = document.createElement("input");
size.setAttribute("type", "text");
size.style.width = "50px";
size.style.textAlign = "right";
onRendered(function()
size.focus();
//size.style.css = "100%";
);
capacity.append(size);
var multiplier = document.createElement("select");
multiplier.style.width = "45px";
multiplier.append(new Option("MB","MB",true,true));
multiplier.append(new Option("GB","GB"));
multiplier.append(new Option("TB","TB"));
capacity.append(multiplier);
var multi = "MB";
function successFunc()
success(size.value+multi);
function setmultiFunc()
multi = multiplier.options[multiplier.selectedIndex].text;
successFunc();
size.addEventListener("change", successFunc);
size.addEventListener("blur", successFunc);
multiplier.addEventListener("change", successFunc);
multiplier.addEventListener("blur", successFunc);
return capacity;
with:
title:"Capacity", field:"Size", align:"center", width:95, editor:CapacityEditor, sorter:SizeSorter, sortable: true,
So, on that one, there are 'a few' issues.
- I have no idea what the success() is supposed to do
- I'm returning a div hoping that the content would populate the cell
- Whenever I put in a value and make a selection, it does not get saved at all; probably because I'm returning a div in the first place
2nd try: Since the edit does not work, maybe I could use the cell click event instead...
The cell.getElement()
does give me the DIV content for the cell as expected but there is no such thing as a cell.setElement()
, right?
I can create my own div, like in the first try and then use the cell.setValue()
to well, set the value but if I can't display my div in the first place, that doesn't work too good.
Tried cell.getElement().innerHTML = "<div>...</div>"
but nothing (waaaay too easy)
3rd try: Well, let's thing outside the box then (literally)
In other words, lets create a very simple modal, display it on top of the existing cell and then use, again, cell.setValue()
to update the value.
Problem is: how do I get the position of the cell?
Using the built-in editor, the editor:"select"
replaces the cell's div with an input in readonly and created a div in the document body with multiple div and then positions it right below the cell making it look like a dropdown:
<input type="text" readonly="" style="padding: 4px; width: 100%; box-sizing: border-box; height: 100%;">
<div class="tabulator-edit-select-list" style="min-width: 80px; top: 348px; left: 671px;"><div class="tabulator-edit-select-list-item" tabindex="0">10K</div><div class="tabulator-edit-select-list-item" tabindex="0">15K</div><div class="tabulator-edit-select-list-item" tabindex="0">7.2K</div><div class="tabulator-edit-select-list-item active" tabindex="0">na</div></div>
Note the top
and left
style attributes.
Oli is able to do it so there has to be a way, right?
Any help, advise, fix would be much appreciated.
javascript tabulator
add a comment |
I'm trying to edit a cell with an input and a dropdown.
The goal being to edit, in this case, a disk size.
I would therefore need to combine , editor:"input", editor:true, validator:["min:0", "max:999", "numeric"]}
with , editor:"select", editorParams:"MB":"MB", "TB":"TB", "GB":"GB"
The final result being something like 146GB.
1st try:
Since this looks like a custom editor, I wrote this:
var CapacityEditor = function(cell, onRendered, success, cancel, editorParams)
var capacity = document.createElement("div");
capacity.style.width = "100%";
var size = document.createElement("input");
size.setAttribute("type", "text");
size.style.width = "50px";
size.style.textAlign = "right";
onRendered(function()
size.focus();
//size.style.css = "100%";
);
capacity.append(size);
var multiplier = document.createElement("select");
multiplier.style.width = "45px";
multiplier.append(new Option("MB","MB",true,true));
multiplier.append(new Option("GB","GB"));
multiplier.append(new Option("TB","TB"));
capacity.append(multiplier);
var multi = "MB";
function successFunc()
success(size.value+multi);
function setmultiFunc()
multi = multiplier.options[multiplier.selectedIndex].text;
successFunc();
size.addEventListener("change", successFunc);
size.addEventListener("blur", successFunc);
multiplier.addEventListener("change", successFunc);
multiplier.addEventListener("blur", successFunc);
return capacity;
with:
title:"Capacity", field:"Size", align:"center", width:95, editor:CapacityEditor, sorter:SizeSorter, sortable: true,
So, on that one, there are 'a few' issues.
- I have no idea what the success() is supposed to do
- I'm returning a div hoping that the content would populate the cell
- Whenever I put in a value and make a selection, it does not get saved at all; probably because I'm returning a div in the first place
2nd try: Since the edit does not work, maybe I could use the cell click event instead...
The cell.getElement()
does give me the DIV content for the cell as expected but there is no such thing as a cell.setElement()
, right?
I can create my own div, like in the first try and then use the cell.setValue()
to well, set the value but if I can't display my div in the first place, that doesn't work too good.
Tried cell.getElement().innerHTML = "<div>...</div>"
but nothing (waaaay too easy)
3rd try: Well, let's thing outside the box then (literally)
In other words, lets create a very simple modal, display it on top of the existing cell and then use, again, cell.setValue()
to update the value.
Problem is: how do I get the position of the cell?
Using the built-in editor, the editor:"select"
replaces the cell's div with an input in readonly and created a div in the document body with multiple div and then positions it right below the cell making it look like a dropdown:
<input type="text" readonly="" style="padding: 4px; width: 100%; box-sizing: border-box; height: 100%;">
<div class="tabulator-edit-select-list" style="min-width: 80px; top: 348px; left: 671px;"><div class="tabulator-edit-select-list-item" tabindex="0">10K</div><div class="tabulator-edit-select-list-item" tabindex="0">15K</div><div class="tabulator-edit-select-list-item" tabindex="0">7.2K</div><div class="tabulator-edit-select-list-item active" tabindex="0">na</div></div>
Note the top
and left
style attributes.
Oli is able to do it so there has to be a way, right?
Any help, advise, fix would be much appreciated.
javascript tabulator
I'm trying to edit a cell with an input and a dropdown.
The goal being to edit, in this case, a disk size.
I would therefore need to combine , editor:"input", editor:true, validator:["min:0", "max:999", "numeric"]}
with , editor:"select", editorParams:"MB":"MB", "TB":"TB", "GB":"GB"
The final result being something like 146GB.
1st try:
Since this looks like a custom editor, I wrote this:
var CapacityEditor = function(cell, onRendered, success, cancel, editorParams)
var capacity = document.createElement("div");
capacity.style.width = "100%";
var size = document.createElement("input");
size.setAttribute("type", "text");
size.style.width = "50px";
size.style.textAlign = "right";
onRendered(function()
size.focus();
//size.style.css = "100%";
);
capacity.append(size);
var multiplier = document.createElement("select");
multiplier.style.width = "45px";
multiplier.append(new Option("MB","MB",true,true));
multiplier.append(new Option("GB","GB"));
multiplier.append(new Option("TB","TB"));
capacity.append(multiplier);
var multi = "MB";
function successFunc()
success(size.value+multi);
function setmultiFunc()
multi = multiplier.options[multiplier.selectedIndex].text;
successFunc();
size.addEventListener("change", successFunc);
size.addEventListener("blur", successFunc);
multiplier.addEventListener("change", successFunc);
multiplier.addEventListener("blur", successFunc);
return capacity;
with:
title:"Capacity", field:"Size", align:"center", width:95, editor:CapacityEditor, sorter:SizeSorter, sortable: true,
So, on that one, there are 'a few' issues.
- I have no idea what the success() is supposed to do
- I'm returning a div hoping that the content would populate the cell
- Whenever I put in a value and make a selection, it does not get saved at all; probably because I'm returning a div in the first place
2nd try: Since the edit does not work, maybe I could use the cell click event instead...
The cell.getElement()
does give me the DIV content for the cell as expected but there is no such thing as a cell.setElement()
, right?
I can create my own div, like in the first try and then use the cell.setValue()
to well, set the value but if I can't display my div in the first place, that doesn't work too good.
Tried cell.getElement().innerHTML = "<div>...</div>"
but nothing (waaaay too easy)
3rd try: Well, let's thing outside the box then (literally)
In other words, lets create a very simple modal, display it on top of the existing cell and then use, again, cell.setValue()
to update the value.
Problem is: how do I get the position of the cell?
Using the built-in editor, the editor:"select"
replaces the cell's div with an input in readonly and created a div in the document body with multiple div and then positions it right below the cell making it look like a dropdown:
<input type="text" readonly="" style="padding: 4px; width: 100%; box-sizing: border-box; height: 100%;">
<div class="tabulator-edit-select-list" style="min-width: 80px; top: 348px; left: 671px;"><div class="tabulator-edit-select-list-item" tabindex="0">10K</div><div class="tabulator-edit-select-list-item" tabindex="0">15K</div><div class="tabulator-edit-select-list-item" tabindex="0">7.2K</div><div class="tabulator-edit-select-list-item active" tabindex="0">na</div></div>
Note the top
and left
style attributes.
Oli is able to do it so there has to be a way, right?
Any help, advise, fix would be much appreciated.
javascript tabulator
javascript tabulator
asked Mar 27 at 23:16
NickNick
299 bronze badges
299 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Ok, so, if anyone is interested, I was able to get the cell's position using a function found on this forum by meouw (https://stackoverflow.com/a/442474/2868497):
function getOffset( el )
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) )
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
return top: _y, left: _x ;
With the cell's top and left position, I was able to place my div to edit my field:
var globalCellClick = function(e, cell)
var capacity = document.createElement("div");
capacity.style.position = "absolute";
capacity.style.left = getOffset(cell.getElement()).left + "px";
capacity.style.top = getOffset(cell.getElement()).top + "px";
capacity.setAttribute("name", "capacity-edit");
var size = document.createElement("input");
size.setAttribute("type", "", "text");
size.style.width = "47px";
size.style.height = "31px";
size.style.textAlign = "right";
capacity.append(size);
var multiplier = document.createElement("select");
multiplier.style.width = "47px";
multiplier.style.height = "31px";
multiplier.append(new Option("MB","MB",true,true));
multiplier.append(new Option("GB","GB"));
multiplier.append(new Option("TB","TB"));
capacity.append(multiplier);
document.body.appendChild(capacity);
function updateCell()
var multi = multiplier.options[multiplier.selectedIndex].text;
cell.setValue(size.value+multi);
size.focus();
size.addEventListener("change", updateCell);
size.addEventListener("blur", updateCell);
multiplier.addEventListener("change", updateCell);
multiplier.addEventListener("blur", updateCell);
;
with:
title:"Capacity", field:"Size", align:"center", width:95, cellClick:globalCellClick, sorter:SizeSorter, sortable: true,
I can edit the rest of the fields as needed and I'm then using a save button to save the modifications and destroy all the div I created to edit:
$("#tabulator-controls button[name=save-data]").on("click", function()
$("div[name=capacity-edit]").remove();
// update the database
);
There may be an easier/cleaner way to get it done but it works so happy with it.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387917%2ftabulator-4-2-how-to-use-a-multi-element-cell-for-editing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Ok, so, if anyone is interested, I was able to get the cell's position using a function found on this forum by meouw (https://stackoverflow.com/a/442474/2868497):
function getOffset( el )
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) )
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
return top: _y, left: _x ;
With the cell's top and left position, I was able to place my div to edit my field:
var globalCellClick = function(e, cell)
var capacity = document.createElement("div");
capacity.style.position = "absolute";
capacity.style.left = getOffset(cell.getElement()).left + "px";
capacity.style.top = getOffset(cell.getElement()).top + "px";
capacity.setAttribute("name", "capacity-edit");
var size = document.createElement("input");
size.setAttribute("type", "", "text");
size.style.width = "47px";
size.style.height = "31px";
size.style.textAlign = "right";
capacity.append(size);
var multiplier = document.createElement("select");
multiplier.style.width = "47px";
multiplier.style.height = "31px";
multiplier.append(new Option("MB","MB",true,true));
multiplier.append(new Option("GB","GB"));
multiplier.append(new Option("TB","TB"));
capacity.append(multiplier);
document.body.appendChild(capacity);
function updateCell()
var multi = multiplier.options[multiplier.selectedIndex].text;
cell.setValue(size.value+multi);
size.focus();
size.addEventListener("change", updateCell);
size.addEventListener("blur", updateCell);
multiplier.addEventListener("change", updateCell);
multiplier.addEventListener("blur", updateCell);
;
with:
title:"Capacity", field:"Size", align:"center", width:95, cellClick:globalCellClick, sorter:SizeSorter, sortable: true,
I can edit the rest of the fields as needed and I'm then using a save button to save the modifications and destroy all the div I created to edit:
$("#tabulator-controls button[name=save-data]").on("click", function()
$("div[name=capacity-edit]").remove();
// update the database
);
There may be an easier/cleaner way to get it done but it works so happy with it.
add a comment |
Ok, so, if anyone is interested, I was able to get the cell's position using a function found on this forum by meouw (https://stackoverflow.com/a/442474/2868497):
function getOffset( el )
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) )
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
return top: _y, left: _x ;
With the cell's top and left position, I was able to place my div to edit my field:
var globalCellClick = function(e, cell)
var capacity = document.createElement("div");
capacity.style.position = "absolute";
capacity.style.left = getOffset(cell.getElement()).left + "px";
capacity.style.top = getOffset(cell.getElement()).top + "px";
capacity.setAttribute("name", "capacity-edit");
var size = document.createElement("input");
size.setAttribute("type", "", "text");
size.style.width = "47px";
size.style.height = "31px";
size.style.textAlign = "right";
capacity.append(size);
var multiplier = document.createElement("select");
multiplier.style.width = "47px";
multiplier.style.height = "31px";
multiplier.append(new Option("MB","MB",true,true));
multiplier.append(new Option("GB","GB"));
multiplier.append(new Option("TB","TB"));
capacity.append(multiplier);
document.body.appendChild(capacity);
function updateCell()
var multi = multiplier.options[multiplier.selectedIndex].text;
cell.setValue(size.value+multi);
size.focus();
size.addEventListener("change", updateCell);
size.addEventListener("blur", updateCell);
multiplier.addEventListener("change", updateCell);
multiplier.addEventListener("blur", updateCell);
;
with:
title:"Capacity", field:"Size", align:"center", width:95, cellClick:globalCellClick, sorter:SizeSorter, sortable: true,
I can edit the rest of the fields as needed and I'm then using a save button to save the modifications and destroy all the div I created to edit:
$("#tabulator-controls button[name=save-data]").on("click", function()
$("div[name=capacity-edit]").remove();
// update the database
);
There may be an easier/cleaner way to get it done but it works so happy with it.
add a comment |
Ok, so, if anyone is interested, I was able to get the cell's position using a function found on this forum by meouw (https://stackoverflow.com/a/442474/2868497):
function getOffset( el )
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) )
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
return top: _y, left: _x ;
With the cell's top and left position, I was able to place my div to edit my field:
var globalCellClick = function(e, cell)
var capacity = document.createElement("div");
capacity.style.position = "absolute";
capacity.style.left = getOffset(cell.getElement()).left + "px";
capacity.style.top = getOffset(cell.getElement()).top + "px";
capacity.setAttribute("name", "capacity-edit");
var size = document.createElement("input");
size.setAttribute("type", "", "text");
size.style.width = "47px";
size.style.height = "31px";
size.style.textAlign = "right";
capacity.append(size);
var multiplier = document.createElement("select");
multiplier.style.width = "47px";
multiplier.style.height = "31px";
multiplier.append(new Option("MB","MB",true,true));
multiplier.append(new Option("GB","GB"));
multiplier.append(new Option("TB","TB"));
capacity.append(multiplier);
document.body.appendChild(capacity);
function updateCell()
var multi = multiplier.options[multiplier.selectedIndex].text;
cell.setValue(size.value+multi);
size.focus();
size.addEventListener("change", updateCell);
size.addEventListener("blur", updateCell);
multiplier.addEventListener("change", updateCell);
multiplier.addEventListener("blur", updateCell);
;
with:
title:"Capacity", field:"Size", align:"center", width:95, cellClick:globalCellClick, sorter:SizeSorter, sortable: true,
I can edit the rest of the fields as needed and I'm then using a save button to save the modifications and destroy all the div I created to edit:
$("#tabulator-controls button[name=save-data]").on("click", function()
$("div[name=capacity-edit]").remove();
// update the database
);
There may be an easier/cleaner way to get it done but it works so happy with it.
Ok, so, if anyone is interested, I was able to get the cell's position using a function found on this forum by meouw (https://stackoverflow.com/a/442474/2868497):
function getOffset( el )
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) )
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
return top: _y, left: _x ;
With the cell's top and left position, I was able to place my div to edit my field:
var globalCellClick = function(e, cell)
var capacity = document.createElement("div");
capacity.style.position = "absolute";
capacity.style.left = getOffset(cell.getElement()).left + "px";
capacity.style.top = getOffset(cell.getElement()).top + "px";
capacity.setAttribute("name", "capacity-edit");
var size = document.createElement("input");
size.setAttribute("type", "", "text");
size.style.width = "47px";
size.style.height = "31px";
size.style.textAlign = "right";
capacity.append(size);
var multiplier = document.createElement("select");
multiplier.style.width = "47px";
multiplier.style.height = "31px";
multiplier.append(new Option("MB","MB",true,true));
multiplier.append(new Option("GB","GB"));
multiplier.append(new Option("TB","TB"));
capacity.append(multiplier);
document.body.appendChild(capacity);
function updateCell()
var multi = multiplier.options[multiplier.selectedIndex].text;
cell.setValue(size.value+multi);
size.focus();
size.addEventListener("change", updateCell);
size.addEventListener("blur", updateCell);
multiplier.addEventListener("change", updateCell);
multiplier.addEventListener("blur", updateCell);
;
with:
title:"Capacity", field:"Size", align:"center", width:95, cellClick:globalCellClick, sorter:SizeSorter, sortable: true,
I can edit the rest of the fields as needed and I'm then using a save button to save the modifications and destroy all the div I created to edit:
$("#tabulator-controls button[name=save-data]").on("click", function()
$("div[name=capacity-edit]").remove();
// update the database
);
There may be an easier/cleaner way to get it done but it works so happy with it.
answered Mar 28 at 16:02
NickNick
299 bronze badges
299 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387917%2ftabulator-4-2-how-to-use-a-multi-element-cell-for-editing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown