datatable sorting on string as number

前端 未结 3 1184
天命终不由人
天命终不由人 2020-12-20 22:40

i have datatable and i want to sort in as numeric it contains value like 1st,2nd...., here is my code when i sort it it sorts values like 1st,10th,2nd so on how to sort it p

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-20 23:31

    you need to define sType as numeric on the columndef where you want sorting as number

    $('#example').DataTable( {
       "aoColumns": [
          { "sType": "numeric" },
          null,
          null,
          null,
          null
        ],
    // define at the place where sorting should by by numeric
    // other options goes here
    });
    

    // with above the column at index 0 will be sorted by numeric and other columns are normal auto detected. the length of aoColumns should be equal to number of columns.

提交回复
热议问题