José Mota — The blog

Does Datatables need better integration?

01 September 2011

  • datatables
  • Development
  • functional
  • javascript
Over these last two months, I've been working with Datatables, an amazing easy-to-setup steroid machine for HTML tables. For the kind of work I'm doing right now, it suits my needs just perfectly. A couple of weeks ago I needed to build a plugin for DT: MultipleFilters, something that would allow me to filter data by a range. Each column would have a pair of fields and I would have to mix them into the bowl of parameters to send to the server . It looked fun, so I started doing it, hoping to achieve a beautiful Javascript prototype object that would do magic when plugged in by a single letter. As I was finishing building it, I realized some issues had to be fixed. Disclaimer: The plugin does not approach local processing, only server-side.

Push data to the server without using fnServerData

With minimum coupling in mind, I wanted to find a way that allowed to push data to the server without using the fnServerData option in the initializer. That's not what the end user wants, he wants to just download the plugin, place it in and there, it does range filtering. My suggestion here would be an array of functions (perhaps called afnbeforeSend) that allowed any plugin builder to be able to inject parameters to be sent. That way, when my plugin is initialized, I can push my function that injects such parameters and I don't pollute the initializers.

Integrate with other plugins, such as ColVis or ColReorder

Datatables' features that have controls, such as MF, require a DOM object to be returned in the fnInit function. As of now, I am generating the feature with just a button. The actual controls are being appended to the table's footer, with no regard to the column order or state of visualization. At some point in time, I faced a lot of trouble as I watched multiple controls get spawned across the table, as well as the controls not being switched along with the column being reordered nor being hidden / shown when you check a column with ColVis. Wouldn't it be great if both ColVis and ColReorder had some sort of array of callbacks we could populate? When ColVis toggled a column, I could access it and toggle my filter controls accordingly. When ColReorder dragged a column around, I could know which one and to where it moved. All of this without requiring additional initialization and granting cohesion, based on a functional approaching. For what it's worth, I actually had to hack inside ColReorder and add some code in there so I had to accomplish some integration between MF and CR.

So, is there a need for better integration?

Before I jump into the conclusion, I should say that Allan did a great job on building Datatables, it's a remarkable piece of software. I told him that I would risk being stupid to the point of being told to RTFM, but I stand for ease of read as well as ease of use. There should clearly be some plugin development guidelines and I personally volunteer to help build those guidelines. Based on what I know, I would say there is a need to improve integration. If it's not for how it's built, it would by the way it's told.

Creative Commons License

comments powered by Disqus