Skip to main content

In-Place editing with X-Editable using Datatable plugin

Introduction
In-place editing is a trending feature that can be seen in many latest web applications, a popular example would be trello.com where the editing data happens on the web page without any explicit forms or popups. Another such example I could point out is, thoughtplan.com. The in-place editing is very nice in such a way that editing data seems so natural and user friendly.

To enable in-place editing, there are many free JQuery plugins available on the internet. We are discussing a very popular plugin called x-editable. Most of the time we use html tables to display data where in-place editing is enabled. Hence we need another plugin to elegantly display tables with enormous data. We use a famous JQuery plugin called datatable. Both of these plugins are used widely and free to use.

Assumption      : Bootstrap 3, JQuery used Projects

Integration
In order to enable datatable features on any ordinary table found on web page, we should initialise datatable plugin for that table. It's simply a call on the id or class selector of the table. x-editable plugin can be initialized on each field on any table that requires in-place editing. The initialization of x-editable plugin is same as datatable plugin, i.e, id or class selector of the field should be initialized with x-editable plugin. With that you are good to go in-place editing on datatable.

Challenges
One of the many features provided by datatable is pagination. While we integrate x-editable plugin with datatable, often we forget to see how the plugin works on the rows that are hidden by the datatable pagination feature. Hence the in-place editing is not working on the paginated rows or in other words, the rows in the next page. To mitiage such issues, we will need to use the datatable plugin features or api to initialize the in-place editing on all rows hidden by pagination.

Solution
What we proposed to solve this issue is to use drawCallback function option on the datatable object so when each row is drawn, we can decide what should be done with the rows. In this case, we are trying to initialise x-editable plugin on all editable items/fields in all the rows of the datatable. Below is the drawCallback function used for this purpose on datatable object. You can see how the x-editable plugin is initialised on all editable items of all rows. We have used class name selector for the editable field/column.

Code Snippets
$('#CVUsers').DataTable({
                "pagingType": "simple",
                drawCallback: function(settings){
                          var api = this.api();
                          var csrfHeader = $("meta[name='_csrf_header']").attr("content");
                          var csrfToken = $("meta[name='_csrf']").attr("content");

                          $('.editable-action', api.table().body())
                             .editable({
                                         type : 'select',
                                         source : MAKINUSCV.baseURL + '/admin/user/list/action.mk',
                                         url : MAKINUSCV.baseURL + '/admin/user/list/do/action.mk',
                                         ajaxOptions: {
                                             beforeSend: function (xhr){ xhr.setRequestHeader(csrfHeader, csrfToken); }
                                         },
                                         success : function(response, newValue) {
                                          if (response.status == 'error')
                                           return response.msg;
                                         }
                             }).on('hidden', function(e, reason) {
                                   if(reason === 'save') {
                                       api.rows().invalidate('dom').draw();
                                   }
                             });
                },
                responsive: {
                       details: {
                          display: $.fn.dataTable.Responsive.display.childRowImmediate,
                          type: ''
                       }
                }
 });

The above solves two issues inherent on in-place editing with datatable. First, all rows on all pages are enabled with x-editable feature, and secondly, datatable dom is updated hence the sorting or search can find the updated data after editing.

Comments

  1. The blog shares a lot of worthy things. Keep going..

    Article submission sites
    Education

    ReplyDelete
  2. I have to thank you for the efforts you've put in penning this website. I am hoping to check out the same high-grade content from you in the future as well. In truth, your creative writing abilities has encouraged dev me to get my own, personal website now ;)

    ReplyDelete
  3. wonderful article contains lot of valuable information. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
    This article resolved my all queries.good luck an best wishes to the team members.learn digital marketing use these following link
    Digital Marketing Course in Chennai

    ReplyDelete
  4. here you can get more info about Allama Iqbal open university result data and student ID process, application tracking, BA Admission
    Allama iqbal open university

    ReplyDelete
  5. Hi I am from Join Pak Navy I and I really like your work thanks for this information and keep it up you are doing good

    ReplyDelete
  6. Roster of Sindh High Court. Check complete advocate and judge wise roster sittings. You can read more about roster of Sindh High Court.

    ReplyDelete
  7. Thanks for sharing informative post. Tamil typing online is the best tool to translate Tamil to English fast and easy. Tamil typing Software download | Bamini to Unicode

    ReplyDelete
  8. Thanks for your excellent article. It is so good to read a new article.
    ms excel interview questions
    hacking books

    ReplyDelete
  9. It is time to clarify the continuing doubts you have about the difference between CBD Cannabis and hemp

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. The largest, including thousands more every day With games that start every second, lovePoker is the only place that collects
    poker online games from many, be it Upoker, Pppoker, PokerBros, Pokerstars, Sharkscope, Siampoker, Dafabet, IDN Poker, or well known Thai people

    ReplyDelete
  12. it is not the most popular on this list, but fans do love its benefits ดูบอลฟรี . One of these is that no sign up is required, but you can sign up for free to get some convenient options. For instance, it provides intelligent content recommendations and a calendar for you to set up reminders. That way, you never miss your favorite live content. If you do miss it, though, you can always pull it up on Duball24hrs.com recordings.

    ReplyDelete
  13. ​How to download Tamil Novels this one of the best Tamil Novels​ Blog you can download a number of Tamil Novels,Tamil Novels Pdf and Srikala novels, MR Novels For Free Famous Tamil Novels Pdf​ Free Download I like all blog in the website nice Information to download Tamil Novels Free Download.​

    ReplyDelete

Post a comment

Popular posts from this blog

CSRF enabled Ajax requests using Spring Security

Many of you who have worked on Spring Security might be aware of the fact that Spring Security protects applications from Cross Site Request Forgery using _csrf tokens in the request sent to the web server. You can find a detailed understanding in the Spring documentation page . The objective of this post is to explain how to send _csrf tokens in the Ajax requests when we protect our application URL and application access using spring security. How to get CSRF tokens While we submit a form using an application that is protected with Spring Security, the form gets a default hidden parameter in the form body when using <form:form> element. The param contains the _csrf tokens to authenticate the requests in the server. In case we use other ways to create forms, we have to manually include a hidden parameter that contains name as ${_csrf.parameterName} and  value as ${_csrf.token} . For example, <input type= "hidden" name= "${_csrf.parameterName}"

A wonderful technique to reduce website development cost

Websites - Good way to get online presence Websites are very vital to get online presence of any business nowadays. Websites are categorized into two different types. First one is Static Website and second one is Dynamic Website, normally known as web applications. Static websites are most widely used for any business since they help to bring up the online presence more easily and quickly. Depending on the content and features, static websites cost around $300-$700 . It includes web design and development. Apart from that, the business has to spend for hosting space and domain name for the website. Cloud based development is now more prevalent. Building a website and running it will be very easy and cheap using these cloud infrastructure. But the difficulty facing the development of static websites still looms high as it does not matter who provides the infrastructure. The development cost is still same. Technology - LAMP Static websites are developed using HTML and PHP mostly