jquery - Group a single column with letter and name in datatable? -


how can have letter , name grouping single column using rowgrouping plug-in , jquery datatables?

eg: values:

aaa=>1,aaa=>2,aaa=>3,aab=>1,aab=>2,aab=>3,aac=>1,aac=>2,... 

should group (sgroupby) letter a, b, name aaa, aab, aac.

solution

plug-in rowgrouping no longer being developed, not recommend using it. use alternative way perform row grouping shown in row grouping example.

for example, use code below group rows first letter when sorted column containing names.

var table = $('#example').datatable({     "drawcallback": function (settings){         var api = this.api();          // zero-based index of column containing names         var col_name = 0;          // if ordered column containing names         if (api.order()[0][0] === col_name) {             var rows = api.rows({ page: 'current' }).nodes();             var group_last = null;              api.column(col_name, { page: 'current' }).data().each(function (name, index){                 var group = name.substr(0, 1);                  if (group_last !== group) {                     $(rows).eq(index).before(                         '<tr class="group"><td colspan="6">' + group + '</td></tr>'                     );                      group_last = group;                 }             });         }     } }); 

demo

see this jsfiddle code , demonstration.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -