如何通过Tabulator初始化参数全局禁用表头排序?
Got it, let's fix this for you—you absolutely can disable header sorting globally without configuring each column individually, you just had a couple of small issues with your initialization parameters.
The Problem with Your Current Code
Two things were causing the headerSorting:"false" parameter to fail:
- Wrong parameter name: Tabulator uses
headerSort(notheaderSorting) as the global flag to control header sorting. - Incorrect value type: You passed a string
"false"instead of the booleanfalse. In JavaScript, non-empty strings are treated as truthy values, so Tabulator was ignoring your attempt to disable sorting.
Fixed Initialization Code
Here's the corrected version of your code that will globally disable header sorting for the entire table:
var table = new Tabulator("#main", { layout:"fitColumns", tooltipsHeader:true, pagination:"local", paginationSize:10, persistenceMode:true, // Removed quotes around true (it should be a boolean) headerSort:false // Correct global flag to disable all header sorting });
Bonus: Override for Specific Columns (If Needed)
If you ever need to re-enable sorting for a specific column while keeping the global disable in place, you can still set headerSort:true in that column's configuration:
// Example column config that overrides global setting {title:"Name", field:"name", sorter:"string", headerSort:true}
This approach will save you from having to configure every column individually, which is perfect for your scenario with multiple tables of varying dimensions.
内容的提问来源于stack exchange,提问作者Ari Freyr

