type render in SSP not working since 2.1.x

type render in SSP not working since 2.1.x

deimdeim Posts: 3Questions: 0Answers: 0

Link to test case: https://live.datatables.net/mukakawa/2/edit

Description of problem: I use SSP with object syntax and custom rendering function. Since 2.0 the rendering function is separated in a data type definition and registered via DataTable.type(...). I named the custom type in the column definitions explicitly. (see simplified test case 'nameType').

DataTable.type('nameType', {
  render: (data, type, row) => { 
    return type === 'display' ? `${data}, ${row.fname}` : data;
  }
});

new DataTable('#example', {
  serverSide: true,
  ajax: () =>...,
  columns: [
    {
      title: 'Full Name',
      data: 'name',
      type: 'nameType',
    },
    ...
  ],
});

In version 2.0 this was working, even though the type was not registered (or more precisely: not returned by DataTable.types()), render() was called for a custom data type with correct result (test case: concat two data fields in one column, just for testing, my actual use here is far more complicated ;-)).

Since version 2.1 the render function for a custom type (which is defined in column definition) is not called for SSP results.

Question: How can I use custom type rendering on columns with SSP?

Replies

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

    You need to explicitly give the column type using columns.type. With server-side processing the client-side doesn't have access to all of the data and so cannot reliably determine the column type. This gave rise to a number of bugs because the type was changing between pages.

    On reflection, I'm wondering if the change was an incorrect one as you aren't the first to note the change. I'm pondering whether to put it back in and add an option to have it disable the type detection when server-side processing.

    Allan

  • deimdeim Posts: 3Questions: 0Answers: 0

    As you can see in the test case, I type each column explicitly on init. At least the custom type is not recognized when rendering the column cells with SSP. The render function is not called for the type. This happens since v 2.1

    I like the idea of type registration. But it should also work for columns.type Option with SSP (only for render and className, but not for detection, searching and ordering as you mentioned).

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

    Sorry - you are right, there is an error in how I handle this and I'm working on a fix.

    Allan

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

    I think I've addressed it okay in this commit. The change will be in the nightly build soon if you want to try it from there.

    The change is to have server-side processing do type detection as soon as the data is loaded (which is similar to the client-side processing path now). I've also introduced an option to allow the disabling of auto type detection.

    Regards,
    Allan

  • deimdeim Posts: 3Questions: 0Answers: 0

    The nightly build was not updated, I implemented the commit locally.

    After intense testing: Problem solved! THX a lot

    Deim

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

    The nightly build gets cached by CloudFlare's edge servers. You might need to add a query parameter to the URL - I usually use the current date.

    Excellent to hear that has helped - thanks for letting me know. I'll probably do a release on Friday for the change.

    Allan

Sign In or Register to comment.