need to display the image according to the status value

need to display the image according to the status value

Usha_kasi123Usha_kasi123 Posts: 4Questions: 0Answers: 0

Hi Allan, I am new to DataTable Plugin, now a days i am using datatable plugin for pagination, now i am facing one problem.That is

we are using servlet and jsp aplication.My problem is, In database there is no image or any link, but i need to display the image according to the status value.so i have to set the image in JSON response Can you please give me a clarity

Replies

  • zeinerrjzeinerrj Posts: 11Questions: 1Answers: 2

    Hello Usha_kasi123,

    I know how to do this in PHP, so I'll give you some pseudo code and hope you can figure it out from there.

    I'm assuming you're using some form of Datatables ssp processing, so your code probably looks something like:

    tableData = array();
    tableData = Results of your query
    return json_encode( tableData );
    

    For Datatables, a two dimensional array should be returned in the form of tableData[row][column], so you can loop through it and modify it before returning it.

    tableData = Results of your query
    
    status = array();
    status[0] = 1;   // or whatever your status value is such as "overdue"
    status[1] = 7;
    status[2] = 11;
    
    imageSource = array();
    imageSource[0] = "img/statusImg1";  // Image for a status of 1
    imageSource[1] = "img/statusImg7";
    imageSource[2] = "img/statusImg11";
    
    // Let's say the status info is in column index 1
    
    for( row = 0; row < tableData.length; row++; ) {
      for( x = 0; x < status.length; x++; ) {
       if ( tableData[ row ][ 1 ] == status[ x ] {
         tableData[ row ][ 1 ] = '<img src=" ' + imageSource[ x ] + ' ">';
         break;
       }
      }
    }
    
    return json_encode( tableData );
    

    I know this is just an overview, but I hope it gets you close enough so that you can figure out the code.

This discussion has been closed.