1

Update:

Please check and suggest on how to have a column value as link in koGrid and also how can I have double click functionality in kogrid at the same time i.e., age column as link which when clicked takes me to home/about page and when I double click on any row it takes me to home/Index page.

[here] : http://jsfiddle.net/LRY2U/

 {
field: "age", 
displayName: "Age",
cellTemplate: "content"
 }

Thanks Priyanka

Priyanka Chandok
  • 215
  • 1
  • 6
  • 13
  • can you show some code please or better still a working JSfiddle with the issue – Tanner Feb 21 '14 at 10:14
  • Looking at your history of questions, you've asked 9, had 19 answers and only marked 1 as accepted. Have none of the answers been useful? I'd suggest you mark the answers that have helped you most, firstly so that anyone having the same issue will see what fixed/helped your issue and secondly to give some credit to the people that have spent time trying to help you. If no answer helps and you fix the issue, you can answer your own question with your final solution and mark your own answer as correct. – Tanner Feb 21 '14 at 10:32
  • Thanks tanner. I will mark accepted to answers worked for me. I'll post the code for your reference. – Priyanka Chandok Feb 21 '14 at 10:42
  • @Tanner : Please refer to my question for detail reference and let me know the solution please. – Priyanka Chandok Feb 21 '14 at 10:52
  • Could you please set up a [minimal, complete, tested and readable example](http://stackoverflow.com/help/mcve) showing your issue, on jsfiddle, jsbin, plunker or similar service? It would make helping you with your issue easier. – Robert Westerlund Feb 21 '14 at 16:33
  • @Robert /Tanner : Please follow update – Priyanka Chandok Feb 24 '14 at 06:51

1 Answers1

1

The problem is that the row selection handles the mouse click, so we want to ensure that we don't allow the click event to propagate to the row selection handler, which we can do using the method event.stopPropagation.

To get this working, I first changed the ItemViewModel constructor to perform the actual navigation.

function ItemViewModel(name, age) {
    var self = this;

    self.name = name;
    self.age = age;
    self.ageUrl = "/Home/Index/" + self.age;
    function navigateTo(url){
        // Before navigation we want to stop propagation of the event to avoid 
        // other handlers to handle the click and replace the url (this will 
        // ensure the row selection isn't triggered by clicking the age link)
        event.stopPropagation();
        window.location.href = url;
    }
    self.navigateToName = function(){
        navigateTo("/Home/Index?Name=" + self.name);
    };
    self.navigateToAge = function(){
        navigateTo(self.ageUrl);
    };
};

Then I updated your cell template to use properties and methods on the ItemViewModel object.

cellTemplate: "<a data-bind='click: $parent.entity.navigateToAge, attr: {href: $parent.entity.ageUrl}, text: $parent.entity.age'></a>"

And finally also updated the row selection handler to use methods on the ItemViewModel object.

afterSelectionChange: function (rowItem, event) {
    if (event.type == 'click') {
        rowItem.entity.navigateToName();
    }
}

After doing these changes everything worked well for me (if I put it in a custom html page, since jsfiddle isn't very keen on navigations).

Robert Westerlund
  • 4,750
  • 1
  • 20
  • 32