@Cybrilla » Blog Archives

Author Archives: Mohnish Jadwani

About Mohnish Jadwani

I’m a programmer who cares about his craft. I keep myself healthy with Yoga and blog to share my experiences from time to time.

Javascript jQuery jQuery Plugin

Disable sorting of a column when using Datatables

Published by:

Hello,

For a while now, along with other team members I’ve been working on building a payroll software for one of our clients. This is a multitenant application and each tenant can use this software to process the salaries of their employees in addition to certain other functionalities that use employee information.

One such functionality of the application has got to do with the generation of reports and as an application end user(this could probably be a company HR person for example) one might want to generate a report containing certain data of only a selected list of employees. The next question could be, how could one easily filter or sort a table list full of employees to get only a selected list of employees that match certain critera? Turns out there is a jQuery plug-in called [Datatables](http://www.datatables.net/) which converts an HTML table into one which provides a sorting functionality along with an additional set of functionalities like searching and pagination, all, out of the box.

Since there is a need to select only a particular number of employees(based on what was discussed above) for a report that needs to be generated, we’d be selecting the employees using a checkbox that comes as part of each employee record as shown in the screenshot below. The only problem is that datables by default provides sorting for all columns and we didn’t want this to be there for the checkbox column as this is meaningless and could easily confuse an end user.

Datatables with a sorting option on the first column

Datatables with a sorting option on the first column

It took me a while for me to figure out how to disable the sorting on a specific column when using data tables hence I thought I’d share some code on this could be accomplished. The below configuration settings that are passed to datatables, disable the up and down arrow options as shown in the screenshot below for the first column from when the employee data is first loaded on a page. This code was last tested using Datatables 1.10.8 .

Datatables without a sorting option on the first column

Datatables without a sorting option on the first column

Below is how one could pass these options to a datatable. Here example represents the table id that one would specify as part of the HTML table tag.

Here targets[0] represents the first column of the datatable.

Credits

1. Thanks to this discussion within the Datatables forum for some initial leads into the issue.

 

Asset Pipeline Development RailsTips

How to figure out Runtime Dependencies when using Bower via Rails Assets

Published by:

Recently, for one of our client projects we decided to make use of Bower via Rails Assets to better manage Javascript dependencies with respect to the application. This project is on Rails 4.0.13 . For reasons as to why we choose this approach one can refer to the below two blogs –

1. Better Asset Management in Rails Using Rails Assets

2. Bower through Rails Assets

In our application, we were basically replacing the existing dependencies(few of which were placed in vendor/assets/javascripts and others were gems like the jquery-ui-rails) with gems provided to us via the Rails Assets site.

One such third party plugin that we had to replace was the jquery validate plugin. After including the appropriate gem(rails-assets-jquery-validate) from rails-assets site in the gemfile and running bundle to install that gem you might observe from the Gemfile.lock that this gem depends on the rails-assets-jquery-gem.

The BIG question now is, how does the rails-assets-jquery-validate gem(I had installed the gem with version 1.13.1) know which version of the rails-assets-jquery gem it should pick up, given that unlike rubygems.org the current rails-assets site(based on the screenshot below) doesn’t currently list the runtime dependencies required for a gem(which in our case is that we can’t directly find the runtime dependencies for rails-assets-jquery-validate gem).

The workaround

One can find out the exact dependencies required wrt a specific gem by checking out the bower.json file with respect to appropriate code repository corresponding to the gem(in the context of our e.g., this would be for checking out the bower.json file of the rails-assets-jquery-validate gem related code repository) listed on the rails assets site.