Can't get file size plug in to work for sorting - getting unknown parameter error

Can't get file size plug in to work for sorting - getting unknown parameter error

eshanseshans Posts: 11Questions: 3Answers: 0

Hi - Here's my code. There's a table being rendered with a file size showing, 1mb, 24k, and so on. Does this code look right to do this ? I've attached the errror. It's in the columns definition line. Getting an unknown parameter. Any help would be appreciated. Thank you!

  if (!orderAttachmentsDTO[orderItemID]) {
        orderAttachmentsDTO[orderItemID] = $attachmentsTable.DataTable({
          destroy:true,
          data:itemAttachments,
          columns:[orderAttachmentsMap["type": "file-size", "targets": 2]],
          autoWidth:false,
          order: [[ 0, 'asc' ]],
          paging:false,
          dom:'ft',
          searching: false,
          language: {
            emptyTable: ax.L(911),
            zeroRecords: ax.L(911)
          }
        });

Here's the data coming back in the JSON response.

And the error.

Below is the code from the file-size.js

jQuery.fn.dataTable.ext.type.order['file-size-pre'] = function ( data ) {

var units = data.replace( /[\d\.\s]/g, '' ).toLowerCase();
var multiplier = 1;

if ( units === 'kb' ) {
    multiplier = 1000;
}
else if ( units === 'mb' ) {
    multiplier = 1000000;
}
else if ( units === 'gb' ) {
    multiplier = 1000000000;
}
else if ( units === 'tb' ) {
    multiplier = 1000000000000;
}
else if ( units === 'pb' ) {
    multiplier = 1000000000000000;
}
return parseFloat( data ) * multiplier;
};

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    The tech note link /tn/4 is provided so that you can follow the necessary diagnostic steps.

  • kthorngrenkthorngren Posts: 21,169Questions: 26Answers: 4,922

    I'm not sure what orderAttachmentsMap is but I suspect you want to assign the file-size type using columnDefs since there is no targets option for columns. Maybe you want something like this?

    columnDefs: [{"type": "file-size", "targets": 2}],
    

    Kevin

  • eshanseshans Posts: 11Questions: 3Answers: 0

    Thank you. orderAttachmentsMap is just the map where all of the nodes get rendered and displayed in the table. I tried doing what you suggested but getting the same error

  • kthorngrenkthorngren Posts: 21,169Questions: 26Answers: 4,922

    Can you post what the content of orderAttachmentsMap is?

    If its an object then maybe all you need is this, along with the columnDefs:
    columns: orderAttachmentsMap

    If that doesn't help then post the contents so we can see how it lines up with your JSON response.

    Kevin

This discussion has been closed.