|
Overview
Overview of the functionalities provided by the DataTables Editable plugin
Phase-Requirements, Featured Site contentIntroductionJQuery DataTables Editable plugin enhances standard HTML table by adding data management functionalities (adding new records to the table, selecting and deleting records, and editing cells inline) on the client-side. Look of the HTML table when JQuery DataTables Editable plugin is applied is shown below:
There are standard navigation functionalities such as pagination, ordering, filtering by keyword, changing the number of items that should be shown per page. All these functionalities are added by the JQuery http://datatables.net plugin. In addition JQuery DataTables Editable plugin add ability to add new record, select and delete record and edit the cells inline as shown in the figure. This plugin integrates several plugins such as JQuery DataTables, JQuery Editable, JQuery Validation plugins and implement common data management functionalities. All required processing is encapsulated within the plugin, and only required implementation is a server-side code that accepts add, update and delete requests. Server-side code can be implemented in any language (PHP, ASP.NET/C#, Java) as long as plugin interface requirements are met. This page contains short description explaining the features of the plugin. You can download complete example and see how it works. JQuery DataTables Editable Plugin enables user to make the following actions in the table:
Plugin handles all necessary functionalities - only required implementation is server-side logic that handles AJAX requests sent by the plugin. Implementation of client-side web pageFirst step in the integration of JQuery DataTables Editable plugin into the your application is implementation of the client-side page. Detailed instructions about implementation of client-side code can be found here. In this section is shown overview of implementation. There are two important elements that should be added to the client-side web page:
Table SourceThis plugin works with a plain HTML table. Example of the HTML table is shown below: <table id="myDataTable">
<thead>
<tr>
<th>Company name</th>
<th>Address</th>
<th>Town</th>
</tr>
</thead>
<tbody>
<tr id="17">
<td>Emkay Entertainments</td>
<td>Nobel House, Regent Centre</td>
<td>Lothian</td>
</tr>
<tr id="18">
<td>The Empire</td>
<td>Milton Keynes Leisure Plaza</td>
<td>Buckinghamshire</td>
</tr>
<tr id="19">
<td>Asadul Ltd</td>
<td>Hophouse</td>
<td>Essex</td>
</tr>
<tr id="21">
<td>Ashley Mark Publishing Company</td>
<td>1-2 Vance Court</td>
<td>Tyne & Wear</td>
</tr>
</tbody>
</table>As you can see standard HTML table need to be placed in the HTML source of the page. Only difference is that id of the each record need to be placed in the TR tags as an attribute. Initializing JQuery DataTables Editable pluginJQuery DataTables Editable plugin integrates several plugins that add different functionalities to the table. Most important plugin is JQuery DataTables plugin that adds filtering, ordering and pagination functionalities to the table. This plugin is built on the top of DataTables plugin and it adds additional data-management functionalities. JQuery DataTables Editable plugin is initialized using the following code: <script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#myDataTable').dataTable().makeEditable();
});
</script>myDataTable is an id of the HTML table that should be enhanced. First, DataTables plugin is applied to add common table functionalities, and then this table is made editable using the plugin created in this project. Implementation of the server-side pagesWhen the DataTables Editable plugin is initialized, it sends Update, Delete and Add requests to the server-side. Example of AJAX calls sent to the server-side by the plugin is shown in the figure below:
To accept these actions, server-side pages that handles data management requests need to be created. In the following sections is described what should be implemented on the server-side to make this plugin fully functional. Selecting and deleting rowsJQuery DataTables Editable plugin enables user to select and delete rows in the table. When user press delete button, plugin creates an AJAX request to the server-side with information of the id of the record that is deleted. Example of request that is sent to the server-side is: http://www.site.com/folder/DataData?id=22 URL of the delete page can be changed in plugin configuration. id value that is sent to the server-side is placed as an id attribute of <tr> tag. On the server-side, one page that handles delete AJAX requests that accepts one parameter (id) need to be created. Server-side page should return string "ok" if a record is successfully deleted or error message if delete failed. Editing cell valuesEditing cell is done inline by clicking on the table cells. When user finishes with editing AJAX request with cell position and cell value is sent to the server-side. One sever-side page that handles update AJAX requests need to be created. This page should accepts the following parameters:
Server-side page should return value that is updated if cell is successfully updated on the server-side or an error message. Adding new rowsTo enable adding new record you will need to create a custom HTML form where a user can enter information about the new record. When user enter information about new record in the form, these will be posted to the server-side page. On the server-side one page that handles add AJAX requests need to be created. This page should accept input values entered in the form and return id of the new record. Detailed information about adding new records using DataTables Editable plugin can be found here. |
Not sure if it is obvious, but you need to include two js libs:
I got jquery.jeditable.js from the exsamples zip, but there should also be a official source.
In order to allow the user to add new row to the table i have to add a form with the id of formAddNewRow to a aspx page but what if the page is using master page where a form has already been defined. How do i get around this issue?