data-order not work using Ajax datasource

data-order not work using Ajax datasource

edikaedika Posts: 20Questions: 9Answers: 0

I'm trying to set the correct sorting value for a date column.
My table is populated via ajax. The datasource contains 2 values for date field: one to be displayed and formatted depending by the UI language (field:SendDate), and one to be used by datatables for ordering the column (field: DataOrder).
I've tried to use the 'data-order' attribute in the follwing way:

                {
                    "targets": 2,
                    "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).attr("data-order", rowData.DataOrder);
                    }
                }

but it doesn't work.
I've tried setting sort property like in this post

        {
            "data": {
                type: '@data-order',
                sort: '@data-order'
            },
                var rclass = "read";
                if (tipoRecord === 'R')
                    rclass = data.Letto ? "read" : "toread";
                return "<div class='font-size-sm line-height-1 " + rclass + "'>" + data.SendDate + "</div>";
            }
        },

but throw the error Cannot read property 'SendDate' of undefined.
How can I set the correct order for this column?

Thanks

Edika

Answers

  • edikaedika Posts: 20Questions: 9Answers: 0

    Switching for type in render method do the trick

    {
        "data":null,
         "render": function (data, type, row) {
              if (type === 'sort')
                 return data.DataOrder;
               else if (type === 'filter')
                  return data.SendDate;
               var rclass = "read";
               if (tipoRecord === 'R')
                      rclass = data.Letto ? "read" : "toread";
               return "<div class='font-size-sm line-height-1 " + rclass + "'>" + data.SendDate + "</div>";
        }
    },
    
This discussion has been closed.