jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Column header click event not giving correct value
Tagged: jqxGrid ;
This topic contains 3 replies, has 2 voices, and was last updated by Martin 6 years, 8 months ago.
-
Author
-
Hi, I have a jqxGrid in which I customize the column headers by adding an image to it. When I click on the image, a function is called and in that function I am just printing that column’s datafield. But the issue is that I have to click on that particular column header’s image twice to get the correct value. E.g. For the very first time when I click on 2nd column header’s image ,it does not print anything to the console. But when I click on the same column header’s image again, it will print the datafield correctly. Now if I try to click the 3rd column header’s image, it prints the previous column’s datafield. But when I click on 3rd column header’s image again then it gives me the correct value. Is there something that I am missing? I have attached the jseditor link below. Please look into it.
https://jseditor.io/?key=jqxgrid-header-ver-2
thanks
Hello priyamsharma2704,
Actually, in the moment you are printing the datafield of the column that is sorted when you click on an image.
I would suggest you to pass the column’s datafield as an attribute of theelement in the headerRenderer method and then take it by
event.target.getAttribute('datafield')
in addCol(event).I have updated your fiddle Example so you can check this.
Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/Hi Martin, I tried your example, but it looks like “columnHeaderElement” returns all column’s text which have “renderer” function. In the fiddle example if I console.log the “columnHeaderElement”, it give me the column’s text and not the datafields. In the fiddle example the datafields and the texts are same for each column. But in my case all columns have same text but different datafields. Is there a way to pass the column’s datafield instead of column text?
Thanks for the help.
Hello priyamsharma2704,
Then in your case, instead of using the “columnHeaderElement” for displaying the datafield,
you can usethis.datafield
inside the headerRenderer, as here “this” is the context of the grid’s current column.
I’ve updated the Example.Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.