Force DataTable Draw but getting data again from the ColumnsDefs function

Force DataTable Draw but getting data again from the ColumnsDefs function

JasonColeyNZJasonColeyNZ Posts: 11Questions: 4Answers: 0
edited July 2015 in DataTables 1.10

Hi there,

I have a table with a columnDefs function similar to this below...

"columnDefs": [
            {
                "targets": [iVenAmt],
                "mData": function (source, type, val) {
                    if (type === 'set') {
                        source.VendorTotal = val;
                        return;
                    }
                    else if (type === 'display') {
                        return Currency(VendorAmt(source));
                    }
                    else if (type === 'filter') {
                        return VendorAmt(source);
                    }
                    else if (type === 'sort') {
                        return VendorAmt(source);
                    }
                    else return VendorAmt(source);
                },
                "sClass": "text-right"
            },

the function VendorAmt gets its data from two different places in the underlying data depending on a filter switch on the form.

If I do a oTable.Draw() on the form after a filter has been applied using

$.fn.dataTableExt.afnFiltering.push(function (oSettings, aData, iDataIndex) {
    //filtering code here
})
$("#myTable").dataTable().fnDraw();

the resulting table will redraw, but not using the else if (type === 'display') in the columnDefs function

however it columnDefs will be used if I sort on the column.

My question is there anyway I can do a refresh or something that will force the use of the columnDefs 'display' again?

my data is loaded in from an Ajax call, has over a thousand records and comes from a very complex store proc, so just recalling the Ajax isn't really an option I'd like to use?

Any help appreciated... thank you

Jason

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    My question is there anyway I can do a refresh or something that will force the use of the columnDefs 'display' again?

    You need to use the cell().data() or row().data() methods to set the data which will cause the display value to be updated. Otherwise DataTables just uses the display value that it havs previously used since it doesn't know that the data has changed.

    cell().invalidate() and row().invalidate() are two other functions that could also be used.

    Allan

  • JasonColeyNZJasonColeyNZ Posts: 11Questions: 4Answers: 0

    Column().invalidate() could be a good one, just saying, allows the user to invalidate an entire column..

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Yes, I've wondered about that in the past... It will probably be in a future version.

    Allan

  • JasonColeyNZJasonColeyNZ Posts: 11Questions: 4Answers: 0

    thanks for the help and time

This discussion has been closed.