How to get data from column on a row click..

How to get data from column on a row click..

WavfactWavfact Posts: 12Questions: 0Answers: 0
edited December 2010 in General
I am setting up (trying to) a edit/delete link in my table.

Can be seen here http://www(@)fisheragservice(@)com/tm/users(@)html Please replace the (@)'s with .'s (don't want spam bots indexing the page).

When I click the delete image on the right, I want to get the value from the ID column so I can pass it to a server side script to delete the mysql entry.

I'm capturing the click with this:

[code]
$('#datatable tbody tr a.delete img').live( 'click', function (e) {
var rowID = $('a').attr('href');
alert(rowID);

if (!fancyConfirm(rowID, "Are you sure you want to delete this record?", function(ret) { alert(rowID) }))
e.preventDefault();

});
[/code]

I tried storing the ID I needed in the href tag but not sure how to extract it.. Anyone have an idea of the best way to do this?

Replies

  • WavfactWavfact Posts: 12Questions: 0Answers: 0
    I got it figured out..

    [code]
    $('#datatable tbody tr a.delete').live( 'click', function (e) { var rowID = $(this).attr('href');
    alert(rowID);

    if (!fancyConfirm(rowID, "Are you sure you want to delete this record?", function(ret) { alert(rowID) }))
    e.preventDefault();

    });
    [/code]
  • Keyser_SozeKeyser_Soze Posts: 22Questions: 0Answers: 0
    edited January 2011
    Hi !!

    I like the website and design!!! It's really great template [fisheragservice...]

    I'm having same problem as you but im not good with: javascript and ajax
    Please can you help me :( it's been two days that im stuck with this problem.

    Here is my code:


    [code]
    $(document).ready(function() {

    $('#table-depenses').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "./_server_processing_depenses.php"
    } );

    } );
    [/code]

    Data are loaded via this file: ./_server_processing_depenses.php

    this is my table:

    [code]



    id
    Date
    Categorie
    S.Categorie
    Details
    Voiture
    D.Caisse
    D.H.Caisse
    Banque
    N.Ch
  • WavfactWavfact Posts: 12Questions: 0Answers: 0
    You can view the source of my page and see how I did it.. The below should work..

    [code]
    $(document).ready(function() {

    $('#table-depenses').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "./_server_processing_depenses.php"
    "aoColumns": [
    {"bSortable": false, "bSearchable": false,
    "fnRender": function(oObj) {
    var csId = oObj.aData[1];
    return 'Edit';
    }},
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null
    ]

    });
    });
    [/code]
  • Keyser_SozeKeyser_Soze Posts: 22Questions: 0Answers: 0
    Thanks for the answer! I guess it's complicated but i'll try to make it work.
    This problem really makes me sick :s
  • WavfactWavfact Posts: 12Questions: 0Answers: 0
    What you want to do is quite easy with DataTables.. I am a newbie as well and gather all the bits and pieces of my code from these forums and the examples they provide to make mine work.. With a few questions thrown in from time to time.. :)
  • Keyser_SozeKeyser_Soze Posts: 22Questions: 0Answers: 0
    I was really stressed... thinking "what if it's not possible to make it work?! am i wasting my time?!"

    I used the plugin tablesorter before and now I changed all my tables to work with DataTables.

    I had a porblem with tables which have large number of data, tablesorter+its plugin pager doesn't have limit and offset when using SELECT query. That's why loading all data may not work. And they told me on forums that it's not easy to add this to the script...

    Now i'm using DataTables and i've never used JSON in addition i'm not really good with javascript and ajax.

    A long story :p

    Thanks again, i'll try to make it work =)
  • Keyser_SozeKeyser_Soze Posts: 22Questions: 0Answers: 0
    I just want to tell you that it woooooorks!!!!

    here is a screenshot of my table :)
    http://data.imagup.com/5/1108911449.png

    Thank you ^^
  • WavfactWavfact Posts: 12Questions: 0Answers: 0
    Great! now if you really want to impress your visitor's.. try wrapping a theme around it.. I am using

    [code]http://themeforest.net/item/terminator-13-different-admin-backend-pages/117412[/code]

    Its only $20 but well worth the price and supports DataTables.. I tried a few others but had too many problems with cross-browser support...
  • Keyser_SozeKeyser_Soze Posts: 22Questions: 0Answers: 0
    That's really coool !
    Yeah it worth the price, it's just $20

    Thanks again, you were very helpful :)
  • DrakoDrako Posts: 73Questions: 0Answers: 0
    Hi Wavfact,

    sorry to disturb you, but can you help me out? im having the same problem as you did, i tried your solution but i dont think i understood it.

    In one of the columns of my table i put this

    [X]

    so i could capture the click and get one of the row cell value and send it to a server side script to delete the entry from a sqlite file.

    i search everywhere here and found out that i probably need to use the fngetdata/fngetposition/fngetnodes functions, but i didnt see you using it, how did you got the rowID so you could delete this row?

    thanks!
  • Keyser_SozeKeyser_Soze Posts: 22Questions: 0Answers: 0
    hi!

    I've found an easy method :)

    @Darko
    You need to add a column to your table:
    http://fbta.tumblr.com/post/1374357393/adding-extra-columns-in-jquery-datatable
    Then you can put the link on the element inside your delete as usual

    After reading the Tuto, here is a code that works:
    http://rapidshare.com/files/441068884/datatables_server_processing_add_extra_column.zip

    Maybe you, also, need to read this:
    http://datatables.net/forums/comments.php?DiscussionID=1581

    Good luck
  • DrakoDrako Posts: 73Questions: 0Answers: 0
    thanks keyser!! i found another solution using fngetdata and position!

    i wish i could use your solution but json doesnt seem to work with sqlite.

    thanks!
  • chamnanchamnan Posts: 2Questions: 0Answers: 0
    [code]$sOutput .= '"'."Modify".' ",';
    [/code]

    Thanks Keyser,

    Finally got it working but where do I add target="_blank" in the above code if i want it to open to a new page?
  • elmarcoelmarco Posts: 1Questions: 0Answers: 0
    Wavfact,

    Thanks for sharing your solution. It helped me out of a jam!
  • aswebtechnologyaswebtechnology Posts: 19Questions: 0Answers: 0
    Thanks wavfact, like others your solution helped me as well. Thanks mate. Cheers !
This discussion has been closed.