New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with using KoGrid in Single Page Application #209

Open
ArmHorse opened this Issue Feb 20, 2013 · 4 comments

Comments

Projects
None yet
3 participants
@ArmHorse
Copy link

ArmHorse commented Feb 20, 2013

I got strange behavior with using KoGrid in single page app - it's adding one more row selection checkbox each time, when I am switching between tabs in my application. To explain better, I have reproduced it here: http://jsfiddle.net/ArmHorse/vXjK7/. Please, advice.

issue

@ArmHorse

This comment has been minimized.

Copy link
Author

ArmHorse commented Feb 21, 2013

Frankly, I am not sure that it's good solution, so posting possible fix for this behavior:

in the grid.js at buildColumns function, now I have:
columnDefs.splice(0, 0, {
but it should be
if (columnDefs[0].field != '\u2714') {
columnDefs.splice(0, 0, {
...
}

@rpallas

This comment has been minimized.

Copy link

rpallas commented Mar 4, 2013

Hi ArmHorse, I have this issue as well. I tried your suggested solution, but columnDefs[0] was sometimes undefined so i added an extra check as follows:

if (columnDefs.length > 0 && columnDefs[0].field != '\u2714') {
        columnDefs.splice(0, 0, {
       ...
       }
}

Otherwise, the fix seems to work.

@rpallas

This comment has been minimized.

Copy link

rpallas commented Mar 4, 2013

Submitted a pull request - #213

@dotNetFollower

This comment has been minimized.

Copy link

dotNetFollower commented Jan 24, 2017

Here is a custom binding to solve the issue and avoid the koGrid source code changing (I really don't like 3rd party source code changing in my project, even if it seems to be abandoned like this one)

ko.bindingHandlers["koGridFixed"] = {
   init: function (element, valueAccessor, allBindingsAccessor, data, context) {
      var gridOptions = ko.utils.unwrapObservable(valueAccessor());
      if (gridOptions && gridOptions.columnDefs) {
         var columnDefsArr = ko.utils.unwrapObservable(gridOptions.columnDefs);
         if (columnDefsArr && columnDefsArr.length > 0 && columnDefsArr[0].field === '\u2714')
            columnDefsArr.splice(0, 1);
      }
 
      return ko.bindingHandlers["koGrid"].init(element, valueAccessor, allBindingsAccessor, data, context);
   }
};

Replace all koGrid binding in views with koGridFixed. I've described these bug and fix in my blog - koGrid: Bug – Checkboxes column duplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment