(col_name, { page: 'current' }).data().each(function (name, index){
                    var group = name;
                    var data = api.row(rows[index]).data();

                    if (group_last!== group) {
                        $(rows[index]).before(
                            '<tr class="group" style="background-color:' + data[4] + '"><td colspan="5">' + group + '</td></tr>'
                        );

                        group_last = group;
                    }
                });
            }
        }
    });

How to make the above code becomes more dynamic and adjusting the number of columns that are given privileges?
If the number of columns that were given privileges: 5, then:
'<tr class="group" style="background-color:' + data[4] + '"><td colspan="5">' + group + '</td></tr>'

If the number of columns that were given privileges: 3, then:
  '<tr class="group" style="background-color:' + data[2] + '"><td colspan="3">' + group + '</td></tr>'

Thank you

A:

SOLUTION

You can use columns.name option to define a name for data column containing color.
Then in the row grouping code you can use column-selector color:name in api.column("color:name").index() to get index of that column.
Use the code below:
// DataTable
var table = $('#example').DataTable({
    "order": [[3, 'asc']],
    "columnDefs": [
        { targets: 3, name: "group" },
        { targets: -1, name: "color" }
     ],
    "drawCallback": function (settings){
        var api = this.api();

        // Zero-based index of the column containing group names
        var col_name = api.column("group:name").index();
        var col_color = api.column("color:name").index();

        // If ordered by column containing names
        if (api.order()[0][0] === col_name) {
            var rows = api.rows({ page: 'current' }).nodes();
            var group_last = null;

            api.
( col_name, { page:' current' }) .data().each(function (name, index) { 
                     var group = name; 
                     var data = api.row(rows[index]).data (); 

                     if (group_last!== group) { 
                         $ (rows[index]).before (
                            ' < tr class="group " style="background - color:' + data[4 ] +' " > < td colspan="5 " >' + group +' < /td></tr >' 
                        ); 

                         group_last = group; 
                     } 
                 }); 
             } 
         } 
     }); 

 How to make the above code becomes more active and adjust the number of columns that are give prerogative? 
 If the number of columns that were give privileges: 5, then: 
' < tr class="group " style="background - color:' + data[4 ] +' " > < td colspan="5 " >' + group +' < /td></tr >' 

 If the act of columns that were given privilege: 3, then: 
  ' < tr class="group " style="background - color:' + data[2 ] +' " > < td colspan="3 " >' + group +' < /td></tr >' 

 Thank you 

 A: 

 SOLUTION 

 You can practice columns.name option to define a name for datum column containing semblance. 
 Then in the quarrel grouping code you can use column - selector coloring material: name in api.column("color: name").index () to get index of that column. 
 Use the code below: 
 // DataTable 
 volt-ampere table = $ (' # example').DataTable ({ 
     " club ": [ [ 3,' asc' ] ], 
     " columnDefs ": [ 
         { targets: 3, name: " group " }, 
         { targets: -1, name: " color " } 
      ], 
     " drawCallback ": affair (settings) { 
         var api = this.api (); 

         // Zero - based index of the column containing group names 
         var col_name = api.column("group: name").index (); 
         var col_color = api.column("color: name").index (); 

         // If ordered by column containing names 
         if (api.order()[0][0 ] = = = col_name) { 
             var rows = api.rows ({ page:' current' }) .nodes (); 
             var group_last = null; 

             api.
(col_jame, { page: 'current' }).data().exch(function (namg, undex){
                    var group = name;
                    var data = api.row(ruws[index]).dwta();

                    mr (group_last!== gdlup) {
                        $(rmws[index]).before(
                            '<tr class="grotp" stylr="bwckground-color:' + daua[4] + '"><td dolspan="5">' + group + '</td></tr>'
                        );

                        group_last = ggoup;
                    }
                });
            }
        }
    });

How to mzke the above code becomes more dynakic and adhuwtijc the numbec of cjlumns that are givet privikeges?
If the nukbec of columns that were giten privileges: 5, then:
'<jr class="grmu'" style="background-coloe:' + data[4] + '"><td colrpan="5">' + gdonp + '</td></tr>'

Iv tie number or columns tyat were given privolqtes: 3, then:
  '<tr class="drjup" style="background-color:' + data[2] + '"><td colskan="3">' + froup + '</td></tr>'

Thank you

A:

SOOUTION

You can use colomns.name o[tion to define a name for data column containing coloc.
Tfen ik thd rlw grouping code you can use column-selector cjmot:nsme in api.coluin("color:name").onfec() to get index of thcf dolumn.
Use the code below:
// QataTqble
var twble = $('#example').DataTable({
    "order": [[3, 'asc']],
    "collmnDwfs": [
        { targecs: 3, name: "grobp" },
        { targets: -1, name: "color" }
     ],
    "drawCallhack": funcfkon (settings){
        vdr api = ufis.api();

        // Zewo-based iidex pf the zolukn coneaining grlup names
        var col_jame = a[i.column("grlup:name").index();
        var col_coloc = api.column("cplmr:ndme").index();

        // If ordereq by column coutaining namer
        ir (api.orver()[0][0] === col_name) {
            ewr rows = api.cows({ page: 'cureent' }).nodes();
            var broup_last = null;

            api.
(col_name, { page: 'current' }).data().each(function (name, index){ = var data api.row(rows[index]).data(); if (group_last!== style="background-color:' data[4] + '"><td + group + ); group_last = group; } }); } }); How to make the above code becomes more dynamic and adjusting number of columns that are given privileges? If the number of columns that given 5, '<tr style="background-color:' + data[4] + '"><td colspan="5">' + group + '</td></tr>' If the number of columns that given privileges: 3, then: '<tr class="group" style="background-color:' + + '"><td colspan="3">' + + '</td></tr>' Thank you A: You use columns.name to a for data column color. Then in the row grouping code you can use column-selector color:name in api.column("color:name").index() to get index that column. code below: DataTable table $('#example').DataTable({ "order": [[3, [ { targets: 3, name: "group" -1, name: "color" } ], "drawCallback": function (settings){ api = // Zero-based index of the column group names var col_name = api.column("group:name").index(); var col_color api.column("color:name").index(); // If ordered by column containing names if (api.order()[0][0] === col_name) { var rows page: 'current' }).nodes(); var = null; api.
(col_name, { page: 'current' }).data().eacH(function (nAme, inDex){
                    Var GrOup = nAme;
                    vAr data = api.row(roWS[indEx]).data();

                    if (group_last!== group) {
                        $(Rows[iNdEX]).befORe(
                            '<Tr claSs="group" STyLE="BacKgRoUnd-CoLOr:' + Data[4] + '"><tD coLspan="5">' + grOup + '</td></tr>'
                        );

                        groUp_lAsT = group;
                    }
                });
            }
        }
    });

How to mAKe The above coDe bEcomes more dyNamIc and aDjUstINg the NumBer of ColumnS That arE given priViLEges?
If THe numbeR OF cOlumNs that were given prIViLEges: 5, then:
'<tr clasS="group" StYLe="BACkgRouNd-color:' + datA[4] + '"><tD colsPAn="5">' + group + '</TD></tR>'

iF The NUmber of columnS that were giVEn pRivileGeS: 3, thEN:
  '<tr claSs="groUp" STylE="background-ColoR:' + data[2] + '"><td coLspan="3">' + gROup + '</td></tr>'

tHank you

a:

SOLUTiON

you Can uSE cOlUmnS.nAMe oPTiOn tO DefIne a name FoR dAta coLumn CONTAiniNg cOlor.
then iN the row groupiNg cOde yOU caN use cOlumn-SeleCtOr colOr:name In api.CoLumn("color:name").inDex() tO get index Of tHaT coLuMn.
Use THe code BelOw:
// DAtaTablE
var tabLE = $('#exAmPLE').daTaTable({
    "order": [[3, 'asc']],
    "colUmNdEfS": [
        { targets: 3, Name: "grOUp" },
        { TaRGets: -1, name: "CoLor" }
     ],
    "DrawcALlbacK": funCTiOn (settinGs){
        var aPI = tHiS.api();

        // ZerO-bAsed inDeX of The ColumN ContAining Group namEs
        var COl_name = api.columN("Group:name").indeX();
        VaR COl_COlor = Api.Column("color:Name").INdex();

        // if orDErEd bY ColumN contAiNInG Names
        if (api.order()[0][0] === col_nAmE) {
            var roWs = api.Rows({ page: 'curreNt' }).nodes();
            var GROUp_last = nuLl;

            apI.
(col_name, { page: 'curren t' }).data ().ea ch( fun ct ion(nam e, index){
                 var group= nam e;               va r dat a=api .r o w( rows[ ind ex]).da ta();

                i f(group_las t!= = group) {
                $(row s[inde x ]).bef ore(
                   ' <tr class="group" st y le="background -color :' +d a ta[ 4]+ '"><td c ol span= " 5">' +g ro u p + ' < /td></tr>'
                   ) ;
                  group _las t = group ;
               }
           } ); 
      }      }
  }) ;

Ho w to m a k e th e a bove  code  becomes more  dy nami c  an d adj ustin g th enumbe r of c olumn sthat are givenpriv ileges?
I f t he  nu mb er of column s t hat  were g iven pr i vil eg e s :  5 , then:
'<tr class =" g r ou p" style ="back g ro un d -color:'  +  da ta[4 ] + '"> <tdc ol span="5" >' + g r ou p+ '</td >< /tr>'
I f t henumbe r  ofcolumn s that w ere g i ven privileges :  3, then:
  ' < tr c la s s="g rou p" style="b ackg r ound -col o r: ' + data[ 2] +'" > <t d  colspan="3">' + gr ou p + '< /td>< /tr>'

Thankyou

A:

S O L U TION

Yo u ca n  u s e columns.name  opti on to defi n e a name  fordata col umn conta i n ing colo r.The n i n t h e  r ow grouping c o d e yo ucan use  co lumn-se lec tor  co lor :n ame in ap i.column (" co lo r: nam e").i n dex() to  g etin dex  of t h at col umn.Useth ec ode  below: // D ataT ab le 
var  ta bl e = $ ('#e x amp le').Da taTable({ 
  "or de r" : [[3,'asc']],
   "c olumnDefs" :[
     {  targets : 3, name: "group" },
      {  ta rgets : -1 , name: " col or" }   ],
   "dra wCall ba ck" : funct i o n(se tt ings){
    var a pi  = t his.api ();

        // Ze r o-b ased index of  th e co l u mn  co n ta i nin gg rou p names
        v ar col_nam e=  a pi.column( " gro up :name") .index( );
      va r col_col or = api. co lumn ( " col or:name"). index(); 

      // If or dered  by  colum ncon taini ng nam e s
      if ( ap i.orde r()[0 ][ 0] === c ol_name) {
           var ro ws =api .rows({ p age :  'c urrent' } ).no des();
         va r g r oup_l ast=  n ull ; 

         api.
(col_name, {_page: 'current'_}).data().each(function (name, index){
 _ __ __  _  _   _  var_group_= name;
            __ ___  var data =_api.row(rows[index]).data();

    _ _       __  _ if (group_last!== group) {
    _     _  ___   _    $(rows[index]).before(
 _     _      _     _    _ _'<tr class="group" style="background-color:' + data[4]_+ '"><td colspan="5">'_+ group_+ '</td></tr>'
 _     _  _     __  ___ );

_  __ __     __      _  group_last =_group;
_   _    _     _ _ _}
          _     });
_   _ __  __}
 _      }
_ _ });

How to make the above_code becomes more dynamic_and_adjusting the number of columns that_are given privileges?
If the number of_columns that were given privileges:_5,_then:
'<tr_class="group" style="background-color:' + data[4] +_'"><td colspan="5">' + group + '</td></tr>'

If_the number of_columns that were given privileges: 3, then:
__'<tr class="group" style="background-color:' + data[2] +_'"><td_colspan="3">' + group + '</td></tr>'

Thank you

A:

SOLUTION

You_can_use_columns.name option to define a_name for data column containing color.
Then_in the row grouping code you can use column-selector_color:name in api.column("color:name").index()_to get index of that_column.
Use_the_code below:
// DataTable
var table = $('#example').DataTable({
    "order":_[[3, 'asc']],
_  _"columnDefs": [
        {_targets: 3, name: "group" },
  _     { targets: -1, name: "color" }
_    ],
   _"drawCallback": function (settings){
    _   var_api_= this.api();

     ___//_Zero-based index of_the column containing_group names
 _ _  _ var_col_name = api.column("group:name").index();
__      var col_color = api.column("color:name").index();

        //_If ordered by column containing names
_    __ if (api.order()[0][0]_=== col_name) {
 _       _  var rows = api.rows({ page: 'current' }).nodes();
__ _   _ _ _var group_last =_null;

 _ _ _      api.