Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Data Tables

Posted on 2016-08-17
Last Modified: 2016-09-03
I have a DataTable and am able to use some of the previous help I've received on here to add a link to one of the columns that will open a modal.  I need to able to add an event to the table row selection.  I need some examples of how to to this.

I would like to be able to add a background color to the row when it is selected.
Show a Button on the page (that is hidden on page load).
Add an onclick function for the Button that opens a modal and passes some of the data.  

Thank You!
Question by:Crystal Rouse
LVL 29

Expert Comment

ID: 41760475
Do you mean GridView control? Or something else? DataTable is just basically data...
For a GridView see the SelectedIndexChanging event:
LVL 19

Accepted Solution

Manoj Patil earned 500 total points
ID: 41760596
If you are using Javascript DataTables then you can use a css class to change the background color of the row when select that particular row.

.row_selected td {
    background-color: black !important; /* Add !important to make sure override datables base styles */

Check the URL below for changing the row color on row Click event

Try below code
$(document).ready(function() {
    var table = $('#example').DataTable();
    $('#example tbody').on( 'click', 'tr', function () {
        if ( $(this).hasClass('selected') ) {
        else {
    } );
    $('#button').click( function () {
        table.row('.selected').remove().draw( false );
    } );
} );

Open in new window


<table id="example" class="display" cellspacing="0" width="100%">
                <th>Start date</th>
                <th>Start date</th>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Garrett Winters</td>
                <td>Ashton Cox</td>
                <td>Junior Technical Author</td>
                <td>San Francisco</td>
                <td>Cedric Kelly</td>
                <td>Senior Javascript Developer</td>
                <td>Airi Satou</td>

Open in new window

Standard css file which is in JQuery DataTable Package

Author Closing Comment

by:Crystal Rouse
ID: 41782918
Thank you for your help!  It worked.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IFrame in MVC 2 23
Character counter breaks after adding EmojiOne Area 4 23
Code works but breaks when I add one section 4 20
2 separate CSS animations 2 17
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question