Using column data in another column
Using column data in another column
stevenwoolston
Posts: 3Questions: 0Answers: 0
I would like to know how to use column data values in other columns. For example, I want to generate a bootstrap modal window on a CRUD screen and I need the ID of the "clicked" row to pass to my handler and retrieve the JSON data. I don't know if I have to render the database field that stores objID and hide it, or whether the json data can be accessed directly in the dataTable method.
I have two different ideas on how to do this but no idea how to access the data for either idea :)
1. I could put the objID value in the hyperlink for the Name column and then use an OnClick event to do the hard work, or
2. I could use a JQuery selector and event to get the "clicked" item and extract the objID value using javascript
Let me demonstrate with some sample code.
[code]
Name
Description
×
Modify this Item
Name:
Description:
Close
Save changes
$(function() {
var jsTable = $("#jsTable").dataTable({
"sPaginationType": "full_numbers",
"bProcessing": false,
"sAjaxDataProp": "aaData",
"sAjaxSource": "../Handlers/json.ashx",
"bFilter": true,
"bSort": true,
"aoColumns": [
{ // Do I need this?
"mData": "Name",
"mRender": false
},
{
"mData": "Name",
"mRender": function (data, type, full) {
// how can I get the objID value here so I can call a function
// I prefer the JQuery selector approach but an answer to this would be useful to know :)
return "" + data + "";
}
},
{ "mData": "Description" }
]
});
$("#jsTable tbody td").click( function() {
// get the value I need from the triggered event and pass it on to the ShowCRUD function
ShowCRUD( aaData[ID] );
});
function ShowCRUD(ItemID) {
$.getJSON("../Handlers/json.ashx?q=" + ItemID, function (json) {
$("#CRUDDialog #name").val(json.aaData[0].name);
$("#CRUDDialog #description").val(json.aaData[0].description);
});
$("#CRUDDialog").modal("show");
}
});
[/code]
I would appreciate your help with this.
Thanks
Steven
I have two different ideas on how to do this but no idea how to access the data for either idea :)
1. I could put the objID value in the hyperlink for the Name column and then use an OnClick event to do the hard work, or
2. I could use a JQuery selector and event to get the "clicked" item and extract the objID value using javascript
Let me demonstrate with some sample code.
[code]
Name
Description
×
Modify this Item
Name:
Description:
Close
Save changes
$(function() {
var jsTable = $("#jsTable").dataTable({
"sPaginationType": "full_numbers",
"bProcessing": false,
"sAjaxDataProp": "aaData",
"sAjaxSource": "../Handlers/json.ashx",
"bFilter": true,
"bSort": true,
"aoColumns": [
{ // Do I need this?
"mData": "Name",
"mRender": false
},
{
"mData": "Name",
"mRender": function (data, type, full) {
// how can I get the objID value here so I can call a function
// I prefer the JQuery selector approach but an answer to this would be useful to know :)
return "" + data + "";
}
},
{ "mData": "Description" }
]
});
$("#jsTable tbody td").click( function() {
// get the value I need from the triggered event and pass it on to the ShowCRUD function
ShowCRUD( aaData[ID] );
});
function ShowCRUD(ItemID) {
$.getJSON("../Handlers/json.ashx?q=" + ItemID, function (json) {
$("#CRUDDialog #name").val(json.aaData[0].name);
$("#CRUDDialog #description").val(json.aaData[0].description);
});
$("#CRUDDialog").modal("show");
}
});
[/code]
I would appreciate your help with this.
Thanks
Steven
This discussion has been closed.
Replies
Iam facing same problem what you have raised....
But my requirement is I need to show a datatable if user clicks on the column data as a modal window.
If you got answer for your issue please post the same....
Thanks in advance,