display icon in cell

display icon in cell

LitashLitash Posts: 4Questions: 0Answers: 0
edited October 2013 in DataTables 1.9
Hi Allan,

I am newbie in DataTables, and I like this plugin very much. I was wondering how to replace the data with an icon in a table cell. I am using Ajax data source and using mData to assign a function to the cell. My code is:
[code]
$('#CaseTable').dataTable({
"bProcessing": true,
"sAjaxSource": 'api/Case',
"sAjaxDataProp": "",
"bPaginate": true,
"bLengthChange": false,
"bFilter": false,
"bSort": true,
"aaSorting": [[7, 'asc']],
"bInfo": false,
"bAutoWidth": false,

"aoColumnDefs": [
{
"bSortable": false,
"aTargets": [0],
"mData":null
},
{
"bSortable": false,
"aTargets": [1],
"mData": null
},
{
"bSortable": false,
"aTargets": [2],
"mData": function (source, type) {
if (type === 'display') {
if (source.jointID != null) {
return '';
}
else if (source.jointID == null) {
return "";
}
}
}
},
{
"aTargets": [3],
"mData": "caseID"
},
{
"aTargets": [4],
"mData": "subject"
},
{
"aTargets": [5],
"mData": "category"
},
{
"aTargets": [6],
"mData": "caseStatus"
},
{
"aTargets": [7],
"mData": "feedbackDate"
},
{
"aTargets": [8],
"mData": "dueDate"
},
{
"aTargets": [9],
"mData": "caseOwner"
}
]
});
[/code]
The goal is to display an icon () in the cell with index [2] if the source.jointID is not a null value. Now the value is displayed successfully. But every time I reload the page, there is an pop up window says :
[quote] DataTables waring (table id = 'CaseTable'): Requested unknown parameter {mData function} from the data source for row 0 [/quote]
the data type of the jointID is a GUID in my database.

How to solve this problem? Can help me? Thanks in advance!!!

debug code: agicef

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Your function is returning undefined for anything other than the `display` type. You need to return something other than undefined - an empty string would do for example if that is what you want.

    Allan
  • LitashLitash Posts: 4Questions: 0Answers: 0
    Thanks for your hint Allan. Problem solved! The valid code is this:
    [code]
    "aoColumnDefs": [
    {
    "bSortable": false,
    "aTargets": [0],
    "mData": "jointID ",
    "mRender":
    function (data, type, full) {
    if (type === 'set') {
    return;
    }
    else if (type === 'display') {
    if (data !== "") {
    return '';
    }
    }
    else if (type === 'filter') {
    if (data !== "") {
    return '';
    }
    }
    return '';

    }
    }
    [/code]
This discussion has been closed.