I have a data table with a column of alphanumeric values (for example, 'ab1', 'ab2'... 'ab11', 'ac1', 'acr11', 'ac2'). However, when I click on the header in order to sort the column, the data does not appear as "ab1, ab2, ab11, ac1, ac2, acr11" but instead as "ab1, ab11, ab2, ac1, ac2, acr11".
Ideally I would like to sort first by the letters (two or three letters) and then by the numbers sequentially (from 1 to 1000+). It seems that the datatable currently sorts for the letters - which is good - but it does not sort for natural numbers (or perhaps I should say counting numbers).
I have tried using the "natural" sort plugin, to no avail. My own testing of this plugin indicates that it will only sort numbers then letters, not letters than numbers.
Below is working example. Any help or suggestions would be much appreciated!
library(shiny)
library(DT)
d = cbind(
head(iris),
Mixed = c('ab1', 'ab2', 'ab11', 'ac1', 'acr11', 'ac2')
)
shinyApp(
ui = fluidPage(DT::dataTableOutput('tbl')),
server = function(input, output) {
output$tbl = DT::renderDataTable(
d, plugins = 'natural', options = list(
dom = 't',
columnDefs = list(list(type = 'natural', targets = 6))
)
)
}
)