How we can create a data table with all basic features easily? Solution: See this Bootstrap Datatable With Sort, Pagination, and Search, Sorting Table Program.
Previously I have shared a JavaScript table filter program that contains a search input for filtering. But this is a proper data table which has multiple filter options like sort, search, and visible items count also it has a pagination feature. This type of feature will see in multiple places like the ranking table, user management table, etc. This is proper datatable where you can put different conditions to search for a specified item.
Today you will learn to create a sorting data table using bootstrap and some JavaScript libraries. Basically, there is a table with 4 different columns like title, des, date, etc. And row count is above 10, which means there are more than 10 items available in the table. If I talk about features and filtering: first there is a select dropdown for select visible items, like how my items you want to visualize a single page. The second feature is you can search by inputting characters, third is you can sort items in accessing/descending order. The fourth feature is pagination, the items are dived in multiple pages using paging or pagination.
So, today you will learn to create Bootstrap Datatable With Sort, Pagination, and Search functions. There I have used bootstrap for creating the layout and bootstrap datatable library for creating the program. Also, there are some other JS libraries like jQuery and moment.js. As you know bootstrap’s JS files can’t run without jQuery. You can use this data table program on your website for multiple purposes.
If you are thinking now how this sorting table program actually is, then see the preview given below.
Preview Of Sorting Data Table
See this video preview to getting an idea about how this data table program looks like.
Now you can see this program visually, also you can see it live by pressing the button given above. If you like this, then get the source code of its.
You May Also Like:
Bootstrap Datatable With Sort, Pagination, and Search Source Code
Before sharing source code, let’s talk about it. First I have created the divs according bootstrap grid layout, inside the divs I have created the table using <tr> <td> etc HTML table commands. I did not create any div or input of other features like pagination, search, etc. All these are based on libraries which I have linked. In the HTML file, I have linked bootstrap’s CSS and JS both files, jQuery, and the jQuery datatable plugin.
Now using CSS I have only gave values like color, margin, padding, etc to the table. Also used CSS @media query to reduce the size of some elements and block some in small screen sizes. The JavaScript file contains only 3-4 lines of codes, because it based on multiple libraries. As we know libraries save our time and effort.
Left all other things you will understand after getting the codes, I can’t explain all in writing. For creating this program, you have to create 3 files. First file for HTML, second for CSS, and the third file for JavaScript. Follow the steps to creating this program without any error.
index.html
Create an HTML file named ‘index.html‘ and put these codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
<!DOCTYPE html> <!-- Code By Webdevtrick ( https://webdevtrick.com ) --> <html lang="en" > <head> <meta charset="UTF-8"> <title>Bootstrap Datatable | Webdevtrick.com</title> <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/css/dataTables.bootstrap.min.css'> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,500" rel="stylesheet"/> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <link rel="stylesheet" href="style.css"> </head> <body> <div class="row"> <div class="container"> <h1>Bootstrap 3 SortTable</h1> <table class="table responsive" id="sort"> <thead> <tr> <th scope="col">Title</th> <th scope="col">Authors</th> <th scope="col">Journal</th> <th scope="col">Date</th> </tr> </thead> <tbody> <tr> <td data-table-header="Title">Parent Adolescent Relationship Factors and Adolescent Outcomes Among High-Risk Families.</td> <td data-table-header="Authors">Matthew Withers, Lenore McWey, Mallory Lucier-Greer</td> <td data-table-header="Journal">Family Relations</td> <td data-table-header="Date">Jan. 2017</td> </tr> <tr> <td data-table-header="Title">Prescription Drugs and Nutrient Depletion: How Much is Known?</td> <td data-table-header="Authors">Wendimere Reilly, Jasminka Ilich</td> <td data-table-header="Journal">Advances in Nutrition: An International Review Journal</td> <td data-table-header="Date">Jan. 2017</td> </tr> <tr> <td data-table-header="Title">Relation of Adiponectin with Body Adiposity and Bone Mineral Density in Older Women.</td> <td data-table-header="Authors">Pegah Jafari Nasabian, Julia Inglis, Miranda Ave, Hayley Hebrock, Katie Hall, Sara Nieto, Jasminka Ilich</td> <td data-table-header="Journal">Advances in Nutrition: An International Review Journal</td> <td data-table-header="Date">Jan. 2017</td> </tr> <tr> <td data-table-header="Title">Benefits of whole-body vibration training on arterial function and muscle strength in young overweight/obese women.</td> <td data-table-header="Authors">Alvarez-Alvarado S, Jaime SJ, Ormsbee MJ, Campbell JC, Post J, Pacilio J, Figueroa A.</td> <td data-table-header="Journal">Hypertension Research International Journal</td> <td data-table-header="Date">Jan. 2017</td> </tr> <tr> <td data-table-header="Title">Overexpression of PGC-1α Increases Peroxisomal and Mitochondrial Fatty Acid Oxidation in Human Primary Myotubes.</td> <td data-table-header="Authors">Huang TY, Zheng D, Houmard JA, Brault JJ, Hickner RC, Cortright RN.</td> <td data-table-header="Journal">American Journal of Physiology: Endocrinology and Metabolism</td> <td data-table-header="Date">Jan. 2017</td> </tr> <tr> <td data-table-header="Title">Observed Parenting in Families exposed to Homelessness: Child and Parent Characteristics as Predictors of Response to the Early Risers Intervention.</td> <td data-table-header="Authors">Kendal Holtrop, Timothy F. Piehler, Abigail H. Gewirtz, Gerald J. August</td> <td data-table-header="Journal">Child and Family Well-Beging and Homelessness: Integrating Research into Practice and Policy</td> <td data-table-header="Date">Feb. 2017</td> </tr> <tr> <td data-table-header="Title">Testing the impact of sliding versus deciding in cyclical and non cyclical relationships.</td> <td data-table-header="Authors">Charity E. Clifford, Amber Vennum, Michelle Busk, Frank D. Fincham</td> <td data-table-header="Journal">Personal Relationships: Journal of the International Assoc. for Relationship Research</td> <td data-table-header="Date">Feb. 2017</td> </tr> <tr> <td data-table-header="Title">Personal and Cultural Identity Development in Recently Immigrated Hispanic Adolescents: Links With Psychosocial Functioning.</td> <td data-table-header="Authors">Meca A, Sabet RF, Farrelly CM, Benitez CG, Schwartz SJ, Gonzales-Backen M, Lorenzo-Blanco EI, Unger JB, Zamboanga BL, Baezconde-Garbanati L, Picariello S, Des Rosiers SE, Soto DW, Pattarroyo M, Villamar JA, Lizzi KM.
</td> <td data-table-header="Journal">American Psychological Association: Cultural Diversity & Ethnic Minority Psychology</td> <td data-table-header="Date">Feb. 2017</td> </tr> <tr> <td data-table-header="Title">School burnout and intimate partner violence: The role of self-control.</td> <td data-table-header="Authors">AN Cooper, GS Seibert, RW May, MC Fitzgerald, FD Fincham</td> <td data-table-header="Journal">Personality and Individual Differences</td> <td data-table-header="Date">Feb. 2017</td> </tr> <tr> <td data-table-header="Title">Efficacy Of The Repetitions In Reserve-Based Rating Of Perceived Exertion For The Bench Press In Experienced And Novice Benchers.</td> <td data-table-header="Authors">Ormsbee MJ, Carzoli JP, Klemp A, Allman BR, Zourdos MC, Kim JS, Panton LB.</td> <td data-table-header="Journal">The Journal of Strength and Conditioning Research</td> <td data-table-header="Date">March 2017</td> </tr> <tr> <td data-table-header="Title">Exercise training reverses age-induced diastolic dysfunction and restores coronary microvascular function.</td> <td data-table-header="Authors">Hotta K, Chen B, Behnke BJ, Ghosh P, Stabley JN, Bramy JA, Sepulveda JL, Delp MD, Muller-Delp JM.</td> <td data-table-header="Journal">The Journal of Physiology</td> <td data-table-header="Date">March 2017</td> </tr> <tr> <td data-table-header="Title">Macronutrient Intake and Distribution in the Etiology, Prevention and Treatment of Osteosarcopenic Obesity.</td> <td data-table-header="Authors">Kelly OJ, Gilman JC, Kim Y, Ilich JZ.</td> <td data-table-header="Journal">Current Aging Science</td> <td data-table-header="Date">May 2017</td> </tr> <tr> <td data-table-header="Title">Perception in Romantic Relationships: a Latent Profile Analysis of Trait Mindfulness in Relation to Attachment and Attributions.</td> <td data-table-header="Authors">JG Kimmes, JA Durtschi, FD Fincham.</td> <td data-table-header="Journal">Mindfulness</td> <td data-table-header="Date">April 2017</td> </tr> <tr> <td data-table-header="Title">Individual Differences in Adolescents’ Emotional Reactivity across Relationship Contexts.</td> <td data-table-header="Authors">Cook EC, Blair BL, Buehler C.</td> <td data-table-header="Journal">Journal of Youth Adolescence</td> <td data-table-header="Date">April 2017</td> </tr> <tr> <td data-table-header="Title">Is Plus Size Equal? The Positive Impacts of Average and Plus Sized Media Fashion Models on Women’s Cognitive Resource Allocation, Social Comparisons, and Body Satisfaction. [in press]</td> <td data-table-header="Authors">RB Clayton, JL Ridgway, J Hendrickse.</td> <td data-table-header="Journal">Communication Monographs</td> <td data-table-header="Date">April 2017</td> </tr> <tr> <td data-table-header="Title">Effects of Tart Cherry Juice on Brachial and Aortic Hemodynamics, Arterial Stiffness, and Blood Biomarkers of Cardiovascular Health in Adults with Metabolic Syndrome.</td> <td data-table-header="Authors">Sarah Johnson, Negin Navaei, Shirin Pourafshar, Salvador Jaime, Neda Akhavan, Stacey Alvarez-Alvarado, Nicole Litwin, Marcus Elam, Mark Payton, Bahram Arjmandi, Arturo Figueroa.</td> <td data-table-header="Journal">Journal of Federation of American Societies for Experimental Biology</td> <td data-table-header="Date">April 2017</td> </tr> <tr> <td data-table-header="Title">Parenting Styles and College Enrollment: A Path Analysis of Risky Human Capital Decisions.</td> <td data-table-header="Authors">J Kimmes, S Heckman</td> <td data-table-header="Journal">Journal of Family and Economic Issues</td> <td data-table-header="Date">May 2017</td> </tr> <tr> <td data-table-header="Title">Emerging Adult Relationship Transitions as Opportune Times for Tailored Interventions.</td> <td data-table-header="Authors">A Vennum, JK Monk, BK Pasley, FD Fincham</td> <td data-table-header="Journal">Emerging Adulthood</td> <td data-table-header="Date">May 2017</td> </tr> <tr> <td data-table-header="Title">Watermelon and L-Arginine Consumption Regulate Gene Expression Related to Serum Lipid Profile, Inflammation, and Oxidative Stress in Rats Fed on Atherogenic Diet.</td> <td data-table-header="Authors">Joshua Beidler, Shirin Hooshmand, Mark Kern, Arturo Figueroa, Men Young Hong</td> <td data-table-header="Journal">Journal of Federation of American Societies for Experimental Biology</td> <td data-table-header="Date">April 2017</td> </tr> <tr> <td data-table-header="Title">Contribution of Adiponectin to Vascular Responses in Bone Resistance Arteries in Mice.</td> <td data-table-header="Authors">Payal Ghosh, Kazuki Hotta, Tiffany Lucero, Kyle Borodunovich, Morgan Cowan, Jeremy Bramy, Bradley Behnke, Michael Delp, Judy Delp</td> <td data-table-header="Journal">Journal of Federation of American Societies for Experimental Biology</td> <td data-table-header="Date">April 2017</td> </tr> <tr> <td data-table-header="Title">Bone-Protective Effects of Dried Plum in Postmenopausal Women: Efficacy and Possible Mechanisms.</td> <td data-table-header="Authors">Arjmani BH, Johnson SA, Pourafshar S, Navaei N, George KS, Hooshmand S, Chai SC, Akhavan NS</td> <td data-table-header="Journal">Nutrients</td> <td data-table-header="Date">May 2017</td> </tr> <tr> <td data-table-header="Title">Cardiovascular Responses to Unilateral, Bilateral, and Alternating Limb Resistance Exercise Performed Using Different Body Sements.</td> <td data-table-header="Authors">Moreira OC, Faraci LL, de Matos DG, Mazini Filho ML, da Silva SF, Aidar FJ, Hickner RC, de Oliveira CE</td> <td data-table-header="Journal">Journal of Strength and Conditioning Research</td> <td data-table-header="Date">March 2017</td> </tr> </tbody> </table> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/js/jquery.dataTables.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/js/dataTables.bootstrap.min.js"></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.0/moment.min.js'></script> <script src="function.js"></script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put these codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ table { width: 100%; border-collapse: collapse; } tr:nth-of-type(odd) { background: #f4f4f4; } tr:nth-of-type(even) { background: #fff; } th { background: #5cb85c; color: #ffffff; font-weight: 300; } td, th { padding: 10px; border: 1px solid #ccc; text-align: left; } td:nth-of-type(1) { font-weight: 500 !important; } td { font-family: 'Roboto', sans-serif !important; font-weight: 300; line-height: 20px; } span { font-style: italic } @media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) { table.responsive, .responsive thead, .responsive tbody, .responsive th, .responsive td, .responsive tr { display: block !important; } .responsive thead tr { position: absolute !important; top: -9999px; left: -9999px; } .responsive tr { border: 1px solid #ccc; } .responsive td { border: none; border-bottom: 1px solid #eee !important; position: relative !important; padding-left: 25% !important; } .responsive td:before { position: absolute !important; top: 6px; left: 6px; width: 45%; padding-right: 10px; white-space: nowrap !important; font-weight: 500 !important; } .responsive td:before { content: attr(data-table-header) !important; } } |
function.js
The final step, create a JavaScript file named ‘function.js‘ and put the codes.
1 2 3 4 5 6 7 8 |
// Code By Webdevtrick ( https://webdevtrick.com ) $(document).ready(function() { $("#sort").DataTable({ columnDefs : [ { type : 'date', targets : [3] } ], }); }); |
That’s It. Now you have successfully created Bootstrap Datatable With Sort, Pagination, and Search, Sorting Data Table program. If you have any doubt or question comment down below.
Thanks For Visiting, Keep Visiting.
a bit confusing … it is DataTables wuth a biitstrap theme. As opposed to the it being a bootstrap invention.
other than that, you make great stuff … freaking genious!
not able to sort
it work very good, just found some issue under ipad… XD
Not Working with provided code
Not working for me. Only data table display. Sort, Search, Pagination doesn’t display. Please advise. Thank you.