1

I am in the process of fixing a sort issue within one of our applications but I am running into an issue. I am using Slick Grid for my grid implementation. The current sort function in place (not written by myself) works fine with the exception of 1 caveat. It will sort the columns just fine, but I cannot get my checkbox to stay with its respective row when sorting by columns. The checkboxes stay on the same row that they were on initially before the sort, therefore if the user were to enact one of the many functions that is tied to a row being selected, it would be performed on the wrong row. Please let me know if I need to elaborate on this in more detail as it is somewhat hard to explain without observing the behavior.

Brief example of my current setup:

checkboxSelector : new Slick.CheckboxSelectColumn({
              cssClass: "slick-cell-checkboxsel",
        }),

        columns : [{
                id : "name",
                name : NAME,
                field : "name",
                width : 300,
                editor : Slick.Editors.Text,
                sortable : true

I have a few more columns but this is how my row would look. I would have a checkbox, then a name field, then another column, etc.

Now comes my sort method:

APPLICATION.grid.onSort.subscribe(function (e, args) 
{
    var cols = args.sortCols;

    APPLICATION.gridData.sort(function (dataRow1, dataRow2) 
    {
        for (var i = 0, l = cols.length; i < l; i++) 
        {
            var field = cols[i].sortCol.field;
            var sign = cols[i].sortAsc ? 1 : -1;
            var value1 = dataRow1[field], value2 = dataRow2[field];
            var result = (value1 == value2 ? 0 : (value1 > value2 ? 1 : -1)) * sign;

            if (result != 0) 
            {
                return result;
            }
        }

        return 0;
    });

    APPLICATION.grid.invalidate();
    APPLICATION.grid.render();
});

I am new to Slick Grid and have checked their API but cannot come up with any solutions. Does anyone know how I can get my checkbox to stay with its respective row when sorting by columns?

Any help is greatly appreciated.

Thank you!

-Dave F.

MotoDave452
  • 398
  • 1
  • 8
  • 22
  • Mind supporting us with a working JSFiddle setup of yours? Like this [one](http://jsfiddle.net/philcruz/4UyNA/) for example. – kayess Dec 08 '15 at 09:14

1 Answers1

1

dataView.syncGridSelection(grid,true)

I think you may find the answer here, Slickgrid checkbox and filtering problems

Community
  • 1
  • 1
Thejaswy
  • 191
  • 2
  • 9
  • After thoroughly researching the Data View API for Slick Grid, this does seem to be a good approach. However, the person who wrote this before me did not make use of Data View. They declared the grid as follows: APPLICATION.grid = new Slick.Grid("#applicationGrid", APPLICATION.gridData, APPLICATION.columns, APPLICATION.options); where APPLICATION.gridData is an array that data gets passed into. This seems to have taken the place of Data View in this instance and implementing Data View will be a large undertaking. I greatly appreciate your feedback though. Any other ideas? – MotoDave452 Dec 29 '15 at 16:57