Filter records based on column data

Filter records based on column data

prathapprathap Posts: 11Questions: 1Answers: 0
edited March 2014 in DataTables 1.9
My data array contains boolean (yes/no), tinyint (0/1/2) values. In fnCreatedRow function, i change it to respective text to display like below:

[code]
"fnCreatedRow": function (nRow, aData, iDataIndex) {
(aData[3] == 'Yes') ? $(nRow.cells[2]).html("Scheduled") : $(nRow.cells[2]).html("Manual");
}
[/code]

Now when i do search with [quote] Schedule [/quote], i am not getting any data. But if i search with [quote] Yes [/quote], i will get the respective row.

Can someone please give me a solution to search on the column data rather than on data array?

Regards,
Prathap.

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,469 Site admin
    I'd suggest not using fnCreatedRow which is for cell manipulation, but rather use mRender which is for data manipulation.

    The 1.10 documentation discusses this: http://next.datatables.net/manual/orthogonal-data

    Allan
  • prathapprathap Posts: 11Questions: 1Answers: 0
    Thank Allan, we will replace with mRender. But how can it solve the underlying issue i commented in my post. i.e. Filtering on cell data text which is not in the data array?

    Regards,
    Prathap.
  • prathapprathap Posts: 11Questions: 1Answers: 0
    Thanks allan, i solved the issue using mRender.

    [code]
    { "sTitle": "Bill Type",
    "mRender": function (data, type, row) {
    if(type == 'display' || type == 'filter'){
    if (data == 'Yes'){ return "Scheduled";} else {return "Manual";}
    }
    else{ return data;}
    }
    },
    [/code]

    Please confirm, if this is best method for displaying / filtering data irrespective of acutal data returned by JSON array.

    Regards,
    Prathap.
  • allanallan Posts: 63,489Questions: 1Answers: 10,469 Site admin
    This is correct - the underlying issue you mentioned in your post is resolved by using mRender . That is what mRender is there fore :-)

    Allan
  • prathapprathap Posts: 11Questions: 1Answers: 0
    Thanks Allan for the guidance..

    Regards,
    Prathap.
This discussion has been closed.