What is Table?

  • The HTML tables are used to present data in a grid style, such as row and columns
  • Basically we want to create a table which means we must use <table>tag

Bootstrap Tables

  • Simple padding
  • Horizontal line

Bootstrap Tables class

  • Table
  • Table-striped
  • Table-bordered
  • Table-hover
  • Table-condensed

Contextual classes

  • Active - applies the hover color to the table row or table cell
  • Success - successful or positive action
  • Info - natural action or informative changes
  • Warning - that might need attention
  • Danger - dangerous or negative action

Bootstrap has a clean layout for building tables; some of the table elements are supported by bootstrap. Those classes are given below,

TAGDescription
<table>Wrapping element for displaying in a tabular format
<thead>Container element for table header rows<tr> to lable table columns
<tbody>Container element for table rows <tr> in the body of table
<tr>Container element for a set of table cell <td> or <th> that appears on a single row
<td>Default table cell
<th>Special table cell for column tables must be used with in a<thead>
<caption>Description of summery of what the table holds

Creating a Simple Table with Bootstrap

  • The table with basic styling has horizontal divided mode
  • The small cell padding 8px by default
  • <table> element are use
Simple Program for Table
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial scale=1">
  6. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <div class="row">
  11. <h1 class="text-center page-header text-primary">
  12. Bootstrap Tables
  13. </h1>
  14. </div>
  15. <div class="row">
  16. <table class="table">
  17. <thead>
  18. <tr>
  19. <th>Name</th>
  20. <th>Age</th>
  21. <th>City</th>
  22. <th>Contact</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr>
  27. <td>Diamond Antony</td>
  28. <td>23</td>
  29. <td>Salem</td>
  30. <td>1234567890</td>
  31. </tr>
  32. <tr>
  33. <td>Senthil kumar</td>
  34. <td>22</td>
  35. <td>Bangalore</td>
  36. <td>9087654321</td>
  37. </tr>
  38. <tr>
  39. <td>priyanga</td>
  40. <td>21</td>
  41. <td>Chennai</td>
  42. <td>8907654321</td>
  43. </tr>
  44. </tbody>
  45. </table>
  46. </div>
  47. </div>
  48. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  49. <script type="text/css" src="js/jquery"></script>
  50. </body>
  51. </html>
Outpu
Bootstrap

That is the output for basic Bootstrap table

Creating a Table-striped with Bootstrap

  • In this Table-striped class is called as a zebra-striped
  • Using .table-striped class
  • In this table-striped class generate the black and white color
  • The striped on rows with in the <tbody>

Sample program for table-striped

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial scale=1">
  6. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <div class="row">
  11. <h1 class="text-center page-header text-primary">
  12. Bootstrap Tables
  13. </h1>
  14. </div>
  15. <div class="row">
  16. <table class="table table-striped">
  17. <thead>
  18. <tr>
  19. <th>Name</th>
  20. <th>Age</th>
  21. <th>City</th>
  22. <th>Contact</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr>
  27. <td>Diamond Antony</td>
  28. <td>23</td>
  29. <td>Salem</td>
  30. <td>1234567890</td>
  31. </tr>
  32. <tr>
  33. <td>Senthil kumar</td>
  34. <td>22</td>
  35. <td>Bangalore</td>
  36. <td>9087654321</td>
  37. </tr>
  38. <tr>
  39. <td>priyanga</td>
  40. <td>21</td>
  41. <td>Chennai</td>
  42. <td>8907654321</td>
  43. </tr>
  44. </tbody>
  45. </table>
  46. </div>
  47. </div>
  48. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  49. <script type="text/css" src="js/jquery"></script>
  50. </body>
  51. </html>
Output
Bootstrap


Creating a table-bordered with Bootstrap

  • All table contents come with box or border
  • All tables and cells are covered to the borders
  • .table –bordered class is using
  • The rounded corners are around the entire table
Sample program for table-bordered
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial scale=1">
  6. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <div class="row">
  11. <h1 class="text-center page-header text-primary">
  12. Bootstrap Tables
  13. </h1>
  14. </div>
  15. <div class="row">
  16. <table class="table table-bordered">
  17. <thead>
  18. <tr>
  19. <th>Name</th>
  20. <th>Age</th>
  21. <th>City</th>
  22. <th>Contact</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr>
  27. <td>Diamond Antony</td>
  28. <td>23</td>
  29. <td>Salem</td>
  30. <td>1234567890</td>
  31. </tr>
  32. <tr>
  33. <td>Senthil kumar</td>
  34. <td>22</td>
  35. <td>Bangalore</td>
  36. <td>9087654321</td>
  37. </tr>
  38. <tr>
  39. <td>priyanga</td>
  40. <td>21</td>
  41. <td>Chennai</td>
  42. <td>8907654321</td>
  43. </tr>
  44. </tbody>
  45. </table>
  46. </div>
  47. </div>
  48. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  49. <script type="text/css" src="js/jquery"></script>
  50. </body>
  51. </html>
Output
Bootstrap

Creating a Table-hover with Bootstrap
  • Gray color background is generated on hover effect
  • .table-hover class is using
  • The cursor is hovering over the table row when the hover effect is generated

Sample program for table-hover

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial scale=1">
  6. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <div class="row">
  11. <h1 class="text-center page-header text-primary">
  12. Bootstrap Tables
  13. </h1>
  14. </div>
  15. <div class="row">
  16. <table class="table table-hover">
  17. <thead>
  18. <tr>
  19. <th>Name</th>
  20. <th>Age</th>
  21. <th>City</th>
  22. <th>Contact</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr>
  27. <td>Diamond Antony</td>
  28. <td>23</td>
  29. <td>Salem</td>
  30. <td>1234567890</td>
  31. </tr>
  32. <tr>
  33. <td>Senthil kumar</td>
  34. <td>22</td>
  35. <td>Bangalore</td>
  36. <td>9087654321</td>
  37. </tr>
  38. <tr>
  39. <td>priyanga</td>
  40. <td>21</td>
  41. <td>Chennai</td>
  42. <td>8907654321</td>
  43. </tr>
  44. </tbody>
  45. </table>
  46. </div>
  47. </div>
  48. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  49. <script type="text/css" src="js/jquery"></script>
  50. </body>
  51. </html>
Output
Bootstrap

Creating a table-condensed with Bootstrap
  • Using this class makes table more compact by cutting cell padding in half
  • Large number of columns are in your table means that class will be of help
  • .table-condensed class is used

Sample program for table-hover

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial scale=1">
  6. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <div class="row">
  11. <h1 class="text-center page-header text-primary">
  12. Bootstrap Tables
  13. </h1>
  14. </div>
  15. <div class="row">
  16. <table class="table table-condensed">
  17. <thead>
  18. <tr>
  19. <th>Name</th>
  20. <th>Age</th>
  21. <th>City</th>
  22. <th>Contact</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr>
  27. <td>Diamond Antony</td>
  28. <td>23</td>
  29. <td>Salem</td>
  30. <td>1234567890</td>
  31. </tr>
  32. <tr>
  33. <td>Senthil kumar</td>
  34. <td>22</td>
  35. <td>Bangalore</td>
  36. <td>9087654321</td>
  37. </tr>
  38. <tr>
  39. <td>priyanga</td>
  40. <td>21</td>
  41. <td>Chennai</td>
  42. <td>8907654321</td>
  43. </tr>
  44. </tbody>
  45. </table>
  46. </div>
  47. </div>
  48. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  49. <script type="text/css" src="js/jquery"></script>
  50. </body>
  51. </html>

Output

Bootstrap

Contextual classes

  • Contextual classes are used in table row <tr> or table cells<td>
  • Each color indicates some reaction
  • The colors are used to identify the particular locations

Using Contextual classes

  • .active
  • .success
  • .info
  • .warning
  • .danger

Sample program for contextual classes

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial scale=1">
  6. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <div class="row">
  11. <h1 class="text-center page-header text-primary">
  12. Bootstrap Tables
  13. </h1>
  14. </div>
  15. <div class="row">
  16. <table class="table">
  17. <thead>
  18. <tr class="active">
  19. <th>Name</th>
  20. <th>Age</th>
  21. <th>City</th>
  22. <th>Contact</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr class="success">
  27. <td>Diamond Antony</td>
  28. <td>23</td>
  29. <td>Salem</td>
  30. <td>1234567890</td>
  31. </tr>
  32. <tr class="info">
  33. <td>Senthil kumar</td>
  34. <td>22</td>
  35. <td>Bangalore</td>
  36. <td>9087654321</td>
  37. </tr>
  38. <tr class="warning">
  39. <td>priyanga</td>
  40. <td>21</td>
  41. <td>Chennai</td>
  42. <td>8907654321</td>
  43. </tr>
  44. <tr class="danger">
  45. <td>partheeban</td>
  46. <td>21</td>
  47. <td>Dharmaburi</td>
  48. <td>9543216780</td>
  49. </tr>
  50. </tbody>
  51. </table>
  52. </div>
  53. </div>
  54. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  55. <script type="text/css" src="js/jquery"></script>
  56. </body>
  57. </html>
Output
Bootstrap
Responsive Table

  • The table has a horizontal scroll on small devices under 768px
  • When viewing on anything larger than 768px wide you will not see any difference in these tables
  • .table-responsive class is used

Sample program for responsive table

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial scale=1">
  6. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <div class="row">
  11. <h1 class="text-center page-header text-primary">
  12. Bootstrap Tables
  13. </h1>
  14. </div>
  15. <div class="row">
  16. <div class="table-responsive">
  17. <caption>responsive table layout</caption>
  18. <table class="table ">
  19. <thead>
  20. <tr class="active">
  21. <th>Name</th>
  22. <th>Age</th>
  23. <th>City</th>
  24. <th>Contact</th>
  25. </tr>
  26. </thead>
  27. <tbody>
  28. <tr class="success">
  29. <td>Diamond Antony</td>
  30. <td>23</td>
  31. <td>Salem</td>
  32. <td>1234567890</td>
  33. </tr>
  34. <tr class="info">
  35. <td>Senthil kumar</td>
  36. <td>22</td>
  37. <td>Bangalore</td>
  38. <td>9087654321</td>
  39. </tr>
  40. <tr class="warning">
  41. <td>priyanga</td>
  42. <td>21</td>
  43. <td>Chennai</td>
  44. <td>8907654321</td>
  45. </tr>
  46. <tr class="danger">
  47. <td>partheeban</td>
  48. <td>21</td>
  49. <td>Dharmaburi</td>
  50. <td>9543216780</td>
  51. </tr>
  52. </tbody>
  53. </table>
  54. </div>
  55. </div>
  56. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  57. <script type="text/css" src="js/jquery"></script>
  58. </body>
  59. </html>
Output
Bootstrap

This output has the horizontal scroll bar that is the output for responsive table

Conclusion

I hope now you can understand how to use and create the Bootstrap Tables. In the future we can learn about the Bootstrap techniques step by step. Stay tuned.