Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define Cell style for Jquery-Jtable

After return result of jquery-Jtable to client, Generate our needed fields at table tag , but i want to define css for last column of table or last my field in Jquery Jtable options, I mean The "status" column have background which :

if status==1 bgcolor:red , 

if status==2 bgcolor:green ,

if status==3 bgcolor:yellow ,

so I wrote this code :

fields: {
    Status: {
        title: 'RequestStatus',
        width: '4%',
        display: function( data ) {
            ???
        }
    }
}
like image 737
Ali Sarshogh Avatar asked Sep 19 '13 05:09

Ali Sarshogh


2 Answers

According to the jTable API reference, it looks like listClass may be what you are looking for to stylize individual table cells.

listClass, string, default: none

A string value that can be set as class/classes of a cell of this field (td element) in the table. Thus, you can stylize fields in the table.

http://www.jtable.org/ApiReference#fopt-listClass

like image 82
user2669157 Avatar answered Nov 01 '22 22:11

user2669157


Here is a way to allow custom styles on cells by using conditional logic: use the display option in jTable for each row and field(Cell), The following code example demonstrates what I mean:

      <style> 
       .redCell
        {
        } 
      </style>

           //---attribute for J table fields   

       display : function(data){
                     if(data.record.status=="1" return "<div class='redCell'>" + data.record.StatusTitle +"</div>";
                     if ... 
                        ... 
                    }
like image 5
Ali Sarshogh Avatar answered Nov 01 '22 21:11

Ali Sarshogh