Introduction
In this article, I have discussed the problem that developer faces while using dataTable plugin with Asp.net Gridview control and suggested the solution for the same problem. This article is for you, if you are using very famous dataTable jquery plugin with Asp.Net data-bound server controls.Background
jQuery plugindataTable
is vastly used in web applications.
It can be easily integrated with repeater and table.
DataTable
plugin is used to make a normal Gridview/table/repeater to a powerful
table having functionalities such as:
- Dynamically add a new row
- Individual column filtering
- Highlight rows and columns
- Show and hide details about a particular record
- User selectable rows (multiple rows)
- User selectable rows (single row) and delete rows
- Editable rows (with jEditable)
- Submit form with elements in table
- Index column (static number column)
- Show and hide columns dynamically
- Regular expression filtering
DataTable
plugin
gives many more functionalities.
We can convert any table into a jquery datatable by writing below one line query.
//Applying dataTable on table element.
$("#table-id").dataTable();
There is a prerequisite for
dataTable
plugin to function properly.
Which says that the target table must be in a well formed manner by having the 'thead'
and
'tbody'
sections. Here 'tfoot'
section is optional. Below is the example of the an ideal target table:
//Ideal Table structure for applying dataTable plugin.
<table id="table_id">
<thead>
<tr>
<th>
Column 1
</th>
<th>
Column 2
</th>
<th>
etc
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Row 1 Data 1
</td>
<td>
Row 1 Data 2
</td>
<td>
etc
</td>
</tr>
<tr>
<td>
Row 2 Data 1
</td>
<td>
Row 2 Data 2
</td>
<td>
etc
</td>
</tr>
//rest rows...
</tbody>
</table>
In the above table, I have not used tfoot
section because, it is optional. One can also include the 'tfoot' section also if required.
No comments:
Post a Comment