easy way set cell title

easy way set cell title

KamoAKamoA Posts: 19Questions: 6Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

This question has an accepted answers - jump to answer

Answers

  • KamoAKamoA Posts: 19Questions: 6Answers: 0

    var headerdata = ['Delete?','Quote Cd','Customer Code','Major Cat','Minor Cat','Product Code','Factor','Start Date','End Date','Type'];
    var columnwidth = [90,105,195,105,105,180,90,120,120,60];
    var columnalign = ['dt-body-center','dt-body-left','dt-body-left','dt-body-left','dt-body-left','dt-body-left','dt-body-right','dt-body-left','dt-body-left','dt-body-left'];
    var dataSet = [ ['0','020',' ',' ',' ','10010 ','13.49','','','4'],['0','020',' ',' ',' ','16020 ','48.05','07/01/01','06/30/02','4'],['0','020',' ',' ',' ','16040 ','21','','','4'],['0','020',' ',' ',' ','200010 ','65','10/04/01','10/04/02','4'],['0','020',' ',' ',' ','32040 ','41.8','','','4'],['0','020',' ',' ',' ','34010 ','15.32','','','4'],['0','020',' ',' ',' ','50010 ','10','','','P1'],['0','020',' ','010','010',' ','14.56','','','2'],['0','020',' ','010','020',' ','8.75','09/22/01','04/15/02','2'],['0','020',' ','010','060',' ','10.25','','','2'],['0','020',' ','030','010',' ','21','','','4'],['0000000012','0','020',' ','050',' ',' ','8','','','2'],['0000000013','0','020',' ','060','010',' ','10','','','2'],];

    var TipSet = [ ['','O TOOLES RESTAURANTS','','','','6/5 KG/NABISCO BAKING POWDER Description Line 2 10010','','','',''],['','O TOOLES RESTAURANTS','','','','10/500/DIXIE CUP Hilton Hotel Paper Cups','','20010701','20020630',''],['','O TOOLES RESTAURANTS','','','','16/10"/SCOTT PAPER TOWELS','','','',''],['','O TOOLES RESTAURANTS','','','','4/5 KG/CAMPBELLS SOUP, CREAM OF MUSHROOM','','20011004','20021004',''],['','O TOOLES RESTAURANTS','','','','4.54 KG/BACON, PEAMEAL','','','',''],['','O TOOLES RESTAURANTS','','','','4/5 LB/PEPPERONI','','','',''],['','O TOOLES RESTAURANTS','','','','115 s/LEMONS','','','',''],['','O TOOLES RESTAURANTS','','DRY GOODS','BAKING SUPPLIES','','','','',''],['','O TOOLES RESTAURANTS','','DRY GOODS','CEREALS','','','20010922','20020415',''],['','O TOOLES RESTAURANTS','','DRY GOODS','JUICES','','','','',''],['','O TOOLES RESTAURANTS','','MEATS FRESH','BEEF','','','','',''],['','O TOOLES RESTAURANTS','','SEAFOOD','','','','','',''],['','O TOOLES RESTAURANTS','','CLEANING SUPPLIES','SOAPS','','','','',''],];
    var columnsNM = [];
    for (var i in headerdata) {
    columnsNM.push({title: headerdata[i],width: columnwidth[i],className: columnalign[i],});
    }
    $(document).ready( function () {
    $('#GRID_1').DataTable( {
    select: true,
    deferRender: true,
    data: dataSet,
    columns: columnsNM,
    scrollY: '88.76vh',
    scrollCollapse: false,
    orderClasses: false,
    paging: false,
    bFilter: false,
    bLengthChange: false,
    bInfo: false,
    bProcessing: true,
    pageLength: 999,
    processing: true,
    keys: true,
    rowId: function(a){
    return 'DT_' + a.uid;
    },
    columnDefs: [
    {targets: [0],
    visible: false
    },
    {targets: [1],
    render: function ( data, type, row ) {
    if ( type === 'display' ) {
    return '<input type="checkbox" ' + ((data == 'Y') ? 'checked' : '') + ' id="input1" class="filter-ck">';
    }
    return data;
    },
    className: "dt-body-center"
    },
    ],
    } );

    This is my code.
    Is it possible to set easy way titles for each cell?
    May be like:
    title: TipSet,
    I know I can render and make title same as data. In this case my title completely different from data.

    Thank you,

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    You can use createdRow to set the cell's title attribute. Or you can use rowCallback if it can change due to changes in the data. The attribute doesn't need to be based on the row data. You can set it to whatever you like.

    Kevin

  • KamoAKamoA Posts: 19Questions: 6Answers: 0

    Hello Kevin,
    Thank you for you answer. Can you please give me an example how can I use this options with my array 'TipSet'?

    Kamo.

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited November 2020 Answer ✓

    Can you please give me an example how can I use this options with my array 'TipSet'?

    How do you want to use it with your array TipSet?

    Maybe you can start the example and provide details of how you want to use the array.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Take a look at the createRow docs. There are four parameters. The dataIndex parameter might work for accessing the proper element in your TipSet array. The cells parameter is an array of the row cells. Maybe you can loop through the proper TipSet array element to apply the title attributes to the cells.

    Kevin

  • KamoAKamoA Posts: 19Questions: 6Answers: 0

    Kevin,
    Thank you very much.
    I did:

    createdRow: function (row, data, rowIndex) {
        $.each($('td', row), function (colIndex) {
            $(this).attr('title', TipSet[rowIndex][colIndex]);
                          });
                        },
    

    and it works!

This discussion has been closed.