Getting data on click

Getting data on click

vinod_ccvvinod_ccv Posts: 75Questions: 0Answers: 0
edited September 2012 in Editor
Hi,
Please see my initialization. First 5 columns coming from server and next one is for edit/delete. I am looking for a last column in which I have to pass a id variable to make it custom link according to the row i clicked.
[code]
// DataTables init
var oTable=$('#example').dataTable( {
"sDom": "Tfrtip",
"sAjaxSource": "php/browsers.php",

"aoColumns": [
{ "mDataProp": "id" },
{ "mDataProp": "browser" },
{ "mDataProp": "engine" },
{ "mDataProp": "platform" },
{ "mDataProp": "grade", "sClass": "center" },
{ "mDataProp": null,
"sClass": "center",
"sDefaultContent": 'Edit / Delete'
},
{ "mDataProp": null,
"sClass": "center",
[quote] "sDefaultContent": 'MyLink.php?id=$id ' [/quote]
}
]
} );
[/code]


I was trying to find the content of the id when i click the link/image/td of the last column. First step to get content of id was failure, it does nt work( i checked with alert)

[code] ///for dynamic link

$('#example').on('click', 'a.editor_link', function (e) {
e.preventDefault();
// Get the position of the current data from the node
var aPos = oTable.fnGetPosition( this );

// Get the data array for this row
var aData = oTable.fnGetData( aPos[0] ); [/code]

Can any one guide me please. I am looking for solution by which i can get id even if it is hidden.
Thanking you
Vinod

Replies

  • BLSullyBLSully Posts: 24Questions: 1Answers: 0
    edited September 2012
    [code]
    $('#example').on('click', 'a.editor_link', function (e) {
    e.preventDefault();
    var row = $(this).closest('tr'),
    data = oTable._(row),
    id = data[0].id;

    //do something with your id
    });
    [/code]
  • vinod_ccvvinod_ccv Posts: 75Questions: 0Answers: 0
    Hi BLSully,

    Thank you very much. It works for me. Exactly as I expected. I made a custom link button for each row I am in next stage now. Any suggestion in getting this id from new page and use it along with ajax request as an additional variable?. Help is so much appreciated.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    > Any suggestion in getting this id from new page

    What new page?

    > use it along with ajax request as an additional variable?

    Can you not just put the id into the `data` parameter of the jQuery ajax call?
  • BLSullyBLSully Posts: 24Questions: 1Answers: 0
    @vinod_ccv: See what allan said. Guessing you're looking for something like:

    [code]
    //put this code where I have "//do something with your id" in first post
    $.ajax({
    url: '/some/end/point',
    data: { "id": id, "myOtherVar": someOtherData }, //send parameters as needed
    success: function(json) {
    //do stuff on successful return here
    }
    });
    [/code]

    If this is not what you're looking for... please expand on your question w/ non-working code example, commented so we know what you're trying to do.
  • vinod_ccvvinod_ccv Posts: 75Questions: 0Answers: 0
    edited September 2012
    Thank you Allan , Thank you BLSully,


    Yeah, That is what i m working over now (Putting the id in the ajax call data). But in server end I am using the "browsers.php" as template ,which is there in DataTables-1.9.3/extras/Editor-1.2.1/examples/php folder. Let me know additional scripting required in this file to include it ( id) in 'WHERE' condition for mysql select query . Please suggest.
    [quote] I have grid of 'Products groups' that is displayed in first page from 'Products groups' table. When i click the Link button against each 'Products groups' New php? ID page opens with Product group ID ,In this page I am looking for a grid for Particular group ( filtering using id) from another table 'Product' [/quote]
This discussion has been closed.