Getting row ID value

Getting row ID value

StpdudeStpdude Posts: 30Questions: 0Answers: 0
edited January 2013 in General
So re-doing how our program handles data and now we just need to be able to extract the ID from the first column of our table and it will be passed over to a java method to handle it from there. But now getting caught up on how to get the value of our ID column. Basically all our tables have the first column 'ID' which contain unique values. I have read through about 20 pages of questions on getting IDs back and not a single one has worked yet.

What i want to do is be able to highlight one (or possibly multiple if it isn't too hard) rows, and then click a button which would make a call to a function and pass in the # value from the first row 'ID'. Any help would be great! Heres the code as it stands:

[code]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page session="false" %>











$(document).ready(function() {
$('#demo').html( '' );

var editor = new $.fn.dataTable.Editor( {
"ajaxUrl": 'dataTable/edit',
"domTable": "#example",
"fields": [ {"label": "ID:","name": "id"},
{"label": "Version:", "name": "version" },
{"label": "Name:", "name": "name" },
{"label": "Application Name:", "name": "applicationName" },
{"label": "Application Version:", "name": "applicationVersion" },
{"label": "Availability:", "name": "availability" },
{"label": "Baseline Load:", "name": "baselineLoad" },
{"label": "Color", "name": "color"},
{"label": "Implementation ID", "name": "implementationId"},
{"label": "Quantity", "name": "quantity"},
{"label": "Label", "name": "label"},
{"label": "Location", "name": "location"},
{"label": "Application Owner", "name": "applicationOwner"},
{"label": "Architecture Owner", "name": "architectureOwner"},
{"label": "Data Owner", "name": "dataOwner"},
{"label": "Is Ola Agreed?", "name": "olaAgreed"},
{"label": "Is Recognized", "name": "recognized"},
{"label": "Is Strategic", "name": "strategic"},
{"label": "Resolved Time UTC", "name": "resolvedTimeUTC"}
]
} );

$('#example').dataTable( {
"bJQueryUI": true,
"bPaginate": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 5,
"sDom": 'T<"H"fl>t<"F"ip>',
"sAjaxSource": 'dataTable/getData',
"aoColumns": [
{ "mData": "id", "sTitle": "ID" },
{ "mData": "version", "sTitle":"Version" },
{ "mData": "name", "sTitle": "Name" },
{ "mData": "applicationName", "sTitle": "Application Name" },
{ "mData": "applicationVersion", "sTitle": "Application Version" },
{ "mData": "availability", "sTitle": "Availability" },
{ "mData": "baselineLoad", "sTitle": "Baseline Load"},
{ "mData": "color", "sTitle": "Color"},
{ "mData": "implementationId", "sTitle": "Implementation ID"},
{ "mData": "quantity", "sTitle": "Quantity" },
{ "mData": "label", "sTitle": "Label" },
{ "mData": "location", "sTitle": "Location" },
{ "mData": "applicationOwner", "sTitle": "Application Owner" },
{ "mData": "architectureOwner", "sTitle": "Architecture Owner" },
{ "mData": "dataOwner", "sTitle": "Data Owner" },
{ "mData": "olaAgreed", "sTitle": "Is OLA Agreed" },
{ "mData": "recognized", "sTitle": "Is Recognized?" },
{ "mData": "strategic", "sTitle": "Is Strategic?" },
{ "mData": "resolvedTimeUTC", "sTitle": "Resolved Time UTC" },
{
"mData": null,
"sClass": "center",
"sDefaultContent": 'Delete'
}
],
"oTableTools": {
"sRowSelect": "multi",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
} //close table tools
}); //close DT
} ); //close function











[/code]

As you can see its a mix of trying to use the editor functionality but thats somewhat complex as my work wont pay for the 'full' version, so we are also toying with the idea of using a button at the end of each row with a 'new/edit/delete' links. If we click on the delete button have it call 'deleteMDR+ValueOf'ID' or somethign like that.....

Replies

  • allanallan Posts: 63,389Questions: 1Answers: 10,450 Site admin
    Hi Stpdude,

    I see your trial of Editor has expired. How did you find it? Do you have any questions about Editor, beyond the above? Editor does require a license to continue using it beyond the 15 day trial period.

    Regarding the question above, you can use TableTools to do much of what you are looking for since you are already using it - specifically the fnGetSelectedData method ( http://datatables.net/extras/tabletools/api#fnGetSelectedData ) which will return the data for the rows which are currently selected, including the IDs so you can act on them as required.

    Allan
  • StpdudeStpdude Posts: 30Questions: 0Answers: 0
    Allan-

    Yea we used the trial because the Editor sounded great in theory, but in practice its not going to work with how our program passes data back and forth so we will prob re-write and take it out. But in the mean time its still written in. I actually have a progress meeting with my manager tomorrow afteroon where i need to explain that we are going a diff direction writing our own methods instead of using editor.

    I tried using the fnGetSelectedData, among a few others, but i cant quite get it to work. Do you have a example anywhere of it tied to a click event? Our current new thought is making a column on the end with the delete link, and when its called it calls a URL with the value of the ID column appended to the end of it.
  • allanallan Posts: 63,389Questions: 1Answers: 10,450 Site admin
    > Our current new thought is making a column on the end with the delete link, and when its called it calls a URL with the value of the ID column appended to the end of it.

    Just attach an event listener to the cell and use DataTables' fnGetData to get the data for the row that was clicked on in that case. You can then make the Ajax call needed and manipulate the table via the API.

    Allan
  • StpdudeStpdude Posts: 30Questions: 0Answers: 0
    Thanks for the info Allan :)
    Is there a guide on event listeners? Searched around and i see a few discussions on them but no clear guide? Unless im totally blind which given the espresso high im on right now seems entirely possible.....
This discussion has been closed.