Gridx/Dojo & jQuery : Is there a callback when sorting is completed?

北城余情 提交于 2019-12-10 21:17:30

问题


This table is generated using GridX / dojo in NodeWebkit. The "[BV][B][V]" are links that are handled by jQuery using class selector. However, once I sort the grid, the listeners are unbinded. How do I reapply the click function? Is there a callback when sorting & rendering is complete?


回答1:


There is no callback or event that I know of when sorting is complete in gridx.

However, the whole grid is re-rendered when it is sorted or filtered. So you can use something like:

grid.connect(grid.body, 'onRender', function(){
    $(document).on("click", "a.myBVlink", function() {
      ...
    });
    $(document).on("click", "a.myBlink", function() {
      ...
    });
    $(document).on("click", "a.myVlink", function() {
      ...
    });
});



回答2:


I created a wrapper div and added the click listener to it as -

$('#gridWrapper').on('click','.myLinkClass',function(){
    console.log('clicked');
    console.log(this);
});

gridWrapper is not changed. So the listener remains active and the .myLinkClass selector selects the <a href="#" class="myLinkClass">text</a> in spite of sorting.




回答3:


Like @mccannf initiated I use the re-rendering event. For preventing double working I just use a counting variable and do the work only the second time.
Note: If at initial the grid is empty than I set the counter to 1 because than the event is only called once.

var countRender = 0;
if (grid.store.data.length == 0) countRender=1; 

grid.connect(grid.body, 'onRender', function(gridName){
    if (!countRender++) return;
    countRender=0;
    ...
});


来源:https://stackoverflow.com/questions/25672771/gridx-dojo-jquery-is-there-a-callback-when-sorting-is-completed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!