Preventing Columns in SlickGrid from Being Reordered

Is there a way to prevent specific columns in SlickGrid from being reordered? I have tried looking for a solution but couldn't find one. Unlike the 'resizable' option, there doesn't seem to be an option for each column to allow or disallow reordering. Setting the flag below makes all columns reorderable:

var options = {
  enableColumnReorder: true
};

If you know of any workaround or solution, please let me know. Thanks in advance!

Answer №1

Unfortunately, there isn't a straightforward solution for achieving this particular task. However, upon delving into the source code, it becomes apparent that they are utilizing the jquery sortable plugin. By cleverly integrating an "injection" into the sortable call to include the option cancel or items, we can tailor the behavior of the `sortable` plugin.

Within the column options:

headerCssClass: "disable-reorder"

During initialization:

var origSortable = $.fn.sortable;
$.fn.sortable = function (options) {
  if (options !== null && typeof options === 'object'){
    options.cancel = '.disable-reorder';
  }
  return origSortable.apply(this, arguments);
};

data = [
  //some data
];
grid = new Slick.Grid("#myGrid", data, columns, options);

This modification will effectively restrict the reordering capability of headers bearing the class .disable-reorder.

Although somewhat unconventional and makeshift, this approach is currently the most viable course of action.

Complete demonstration here

Answer №2

If you want to prevent column reordering, you can explicitly disable it and make each column sortable individually.

For instance:

var columns = [
    { id: "title", name: "Title", field: "title", sortable: false },
    { id: "duration", name: "Duration", field: "duration", sortable: true, formatter: dayFormatter },
    { id: "%", name: "% Complete", field: "percentComplete", sortable: true },
    { id: "start", name: "Start", field: "start", formatter: dateFormatter, sortable: true },
    { id: "finish", name: "Finish", field: "finish", formatter: dateFormatter, sortable: true },
    { id: "effort-driven", name: "Effort Driven", field: "effortDriven", sortable: true }
  ];

This code snippet is extracted from their demo available here

Additionally, you can refer to the documentation for column options at https://github.com/mleibman/SlickGrid/wiki/Column-Options

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble setting the focus on a text box following a custom popup

Presenting a stylish message box and attempting to focus on a textbox afterward, however, it's not functioning as expected. Below is the HTML code: <a class="fancyTrigger" href="#TheFancybox"></a> <hr> <div id="TheFancybox">& ...

Verify user using Cognito user pool log-in information

Is it possible to authenticate a user using only user pool credentials without an identity pool/IdentityPoolId? Check out this link for more information: https://github.com/aws/amazon-cognito-identity-js The example provided in the link above specifically ...

What methods can I use to create a peer-to-peer communications platform with PHP, MySQL database, and JavaScript?

Currently, I am encountering the challenge of creating a communication channel between two users on a website (such as a gaming site) using only the technologies specified in the title. I recently created an online chess platform with the aim of allowing ...

What could be causing this JavaScript to output undefined?

const urls = [ "http://x.com", "http://y.com", "http://z.com", ]; for (let j=0; j<urls.length; j++) { setTimeout(function() { console.log(urls[j]); }, 3000); } I'm inserting this code snippe ...

If the next element in the sequence happens to be the final element, then conceal a separate

Continue pressing the downward button consistently on until you reach the bottom. The down arrow should disappear slightly before reaching the end. Is there a way to achieve this using the code provided below? I'm new at this, but I believe I need t ...

Tips for executing an artillery script with customizable parameters

execute my-script.yaml with artillery To access the target, a token is required for authentication. How can I execute the script above using a token? For example: execute my-script.yaml using token 983r2fh29hf2893yr72 ...

What could be causing jQuery document ready to restrict access to global variables?

Currently, I am working on a project that involves three separate JavaScript files (example1.js, example2.js, and example3.js) being scripted into a single HTML file (index.html). These JS files are responsible for making an API call and manipulating the r ...

Step-by-step guide on integrating a specific location into Google Maps using React.js

I'm in the process of revamping my website using Reactjs. I want to incorporate a specific Google location with reviews on the map, similar to how it appears on this example (My current website is built on Wordpress). As of now, all I've been ab ...

Surprising outcomes arise when the results of Three.js EffectComposers are combined, as the Additive and Subtractive effects interact in unexpected

While working on postprocessing in Three.js with EffectComposers and shader passes, I encountered some unexpected behavior when combining the WebGLRenderTargets (renderTarget2) from different composers. My setup involves five composers: three to render sce ...

Manipulating the Document Object Model (DOM) in Google

I typically implement this method to ensure that users adhere to the validation rules before submitting. <a class="waves-effect waves-light btn disabled">Submit</a> But, I recently discovered that by simply removing the disabled class using G ...

Enable lodash access throughout a React Native application

Is it possible to have lodash automatically accessible in all files within a React Native project without needing to import it every time? ...

Safari browser removes spaces after commas in cookie values

I'm encountering an issue when trying to set a session cookie for storing an Address. It seems that whenever I include a comma followed by a space in the cookie's value, Safari automatically removes the spaces after the commas, causing the format ...

Execute the controller function with the value as a parameter

I encountered an issue while attempting to call a function in the c# controller and passing a value. The error message I received was: `'Unable to get property 'then' of undefined or null reference'. I also included the Driver Model but ...

Creating a Select component in React without relying on the Material-UI library involves customizing a dropdown

Is there a way to achieve a material UI style Select component without using the material UI library in my project? I'm interested in moving the label to the top left corner when the Select is focused. export default function App({...props}) { retu ...

Transferring canvas element via socket with JS stack size limit

I'm encountering an issue where I need to transfer a canvas element over sockets using socket.io and Node.js. The code snippet below illustrates my approach: var myCanvas = document.getElementById("myCanvas"); var ctx = myCanvas.getContext("2d"); // ...

Unusual issue in IE causing rendering problems in reporting services

Currently, I am creating a report using Reporting Services 2008, MVC 2, and Ajax as my development technologies. When I generate the report, everything displays perfectly if there is data present. However, if there is no data, the report body gets cut off ...

Tips for Printing a div Element with Horizontal Scrollbars

My webpage has both vertical and horizontal scroll bars, but when I use window.print(), it only prints the visible content in the window. Is there a way to print the entire scrollable content within the window? ...

Navigating through the DOM using JavaScript or regular expressions

I have a DOM string called innerHTML and I am looking to extract or display the node value using either JavaScript's DOM API or JavaScript RegEx. "<nobr> <label class="datatable-header-sortable-child" onmousedown="javascript:giveFeedback(&ap ...

Error: It seems like there was a problem with the injector and the module could not be

Currently, I am encountering an issue with the code below. Whenever I try to run it, I receive the following error: Uncaught Error: [$injector:nomod]. Even though the module name is correct, I am unsure of why this error is occurring. I have double-checked ...

A step-by-step guide on transforming an array of objects into an array of arrays with the help of Ramda

I want to convert the following data: [ { a: 2000, b: 4000 }, { a: 8000, b: 5000 }, { a: 6000, b: 1000 } ]; Into this format: [ [ 2000, 8000, 6000 ], [ 4000, 5000, 1000 ] ]; Using Ramda library. I am able to achieve this using R.reduce functio ...