Help: Need to disable a table row based on the content of one of its cells

Discussion in 'Web Design and Development' started by sk3pt1c, Mar 9, 2012.

  1. sk3pt1c macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #1
    So there's a table being created by PHP of user records, some users are deleted but still show up on the table as deleted and i want to make that row disappear where there is a td that contains the text "deleted".
    i get that this can't be done with CSS cause i don't want to target an attribute but perhaps with javascript?
    so basically i want to get the element that is a table -> td that contains the string "deleted" and set a "display:none" to its parent row.
    Help? :)
    Thanks
     
  2. bpaluzzi macrumors 6502a

    bpaluzzi

    Joined:
    Sep 2, 2010
    Location:
    London
    #2
    Why not set a class of "deleted" on that row?
     
  3. sk3pt1c thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #3
    I can't mess with the table at its creation and it's not certain which rows will be rows with a "deleted" user on them.
    I need a way to target said row with javascript so i can set it to not display at all or at least change its styling to color it a different color so it's more evident that it's about a deleted user
     
  4. bpaluzzi macrumors 6502a

    bpaluzzi

    Joined:
    Sep 2, 2010
    Location:
    London
    #4
    Are the users being deleted after the page is drawn?

    Attach a jQuery call to $(this).parents('tr').addClass('deleted') on your ajax binding. Have the styling in CSS, as normal.
     
  5. sk3pt1c thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #5
    I'm kind of a noob at this, bear with me please
    The table data will be pulled from a database, one of the fields in there is whether the user is deleted or not, so it will fill one td at the end of each tr with the user state.
    What i need to do is find the rows that contain users that are deleted, ie look for a td that contains the word "deleted", and apply some css to it, either by giving it a class name and have the rule for it ready in my css, or by adding the styling via the javascript as a span or something.
    Where would i add the call you suggested in that case?
    Sorry if i'm not making sense :)
     
  6. bpaluzzi macrumors 6502a

    bpaluzzi

    Joined:
    Sep 2, 2010
    Location:
    London
    #6
    No worries -- I'm not quite sure I understand what you're trying to do here, to be honest :)

    If the user status (deleted vs active) is known at page-draw time (i.e., you're not waiting on any user input to set them deleted), I'd go back to setting a class on the tr via php. Are you using any templating language, or just outputting raw HTML via PHP?
     
  7. sk3pt1c thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #7
    I think it's the latter.
    There's no user input, it's just outputting the database table data.
    How would i add the class in the php though?
    I'd still need to find the rows that have "deleted" in them, no?
    I guess i'd rather not mess with the php cause it might affect other files that do the same thing, it's part of a cms...
     
  8. elppa macrumors 68040

    elppa

    Joined:
    Nov 26, 2003
    #8
    Do have access to jQuery?

    If so, you can use contains:
    http://api.jquery.com/contains-selector/

    Code:
    $("td:contains(delete)").closest("tr").hide();
    Of course, you have to be careful that the other cells won't also contain delete!

    Same principle, run in the webkit console on this page:

    Code:
    $("a.bigusername:contains(sk3pt1c)").closest("div.page").fadeOut()
     
  9. Jamesbot macrumors member

    Joined:
    Jun 19, 2009
    #9
    why wouldn't you just do this in the SQL query?
     

Share This Page