Newbie

Newbie

manuelgmanuelg Posts: 3Questions: 1Answers: 0

Hi, I am just starting to play with DataTables and is really nice all the features that it has. But can't seem to find a way to select a row (Just one row and not allow user to select multiple rows) and when the user presses either an EDIT or DELETE button, it will take the user to another page depending on their selection (delete.php or edit.php) and pass the record number or reference to the database on either page (delete.php or edit.php) and allow the user to do it on that particular page.

So far I have found only on the examples, do this BUT with a bubble style. I don't want a bubble OR inline editing. Just want an old fashion separate page for either delete or edit page.

Thanks in advance guys!

This question has an accepted answers - jump to answer

Answers

  • AndersHPAndersHP Posts: 36Questions: 14Answers: 1
    edited June 2015

    Not sure i understand perfectly but here is how i select/unselect stuff. You can use the variable "dataInIndex" for the navigation. Let me know if it works for you

    $('#tableID tbody').on( 'click', 'tr', function () {
            // If row is already selected - unselect it
            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
            }
            // if not - unselect the previous selected, and store value of first cell in a variable
            else {
                table.$('tr.selected').removeClass('selected');
                $(this).addClass('selected');
                var dataInIndex0= table.cell('.selected', 0).data();
          
            }
        } );
    
    
  • manuelgmanuelg Posts: 3Questions: 1Answers: 0

    Looks great but as I said, I am still a newbie on this and was wondering if you could add a button so when the user clicks, it will send the user to another page (edit.php) so in there it could be edited that particular data selected.

    Right now I click on the row and it selects it but there is no button to click to send the user to the other page (in this case edit.php)....

    Thanks for your help! Really appreciate it...

  • AndersHPAndersHP Posts: 36Questions: 14Answers: 1
    Answer ✓

    Something like this maybe

    // have a button some where in your html
    <button id="idOfYourButton">ButtonText</button>
    
    
    var parameter;
    
    
    // sets the parameter variable when a row is clicked
    $('#tableID tbody').on( 'click', 'tr', function () {
            // If row is already selected - unselect it
            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
            }
            // if not - unselect the previous selected, and store value of first cell in a variable
            else {
                table.$('tr.selected').removeClass('selected');
                $(this).addClass('selected');
    
                parameter= table.cell('.selected', 0).data();
           
            }
        } );
    
    
    
    // add callback for button  - use parameter variable for navigation
    $( document ).ready(function() 
    {
          $('#idOfYourButton').click(function() {
               window.location = "www.example.com/index.php?id=" + parameter;
           });
    });
    
  • manuelgmanuelg Posts: 3Questions: 1Answers: 0

    Excellent!!!!

    Thanks

This discussion has been closed.