dataGrid的分页后的javascript调用分页、dataGrid、javascript

2023-09-10 22:10:28 作者:沐白

有没有一种方法来调用JS或jQuery函数事后PrimeFaces的数据网格已经页和数据内容之间进行切换了哪些变化?我必须设置一个jQuery函数,该函数显示在数据网格的项目,因为项目是由页面显示的页面,我不得不重新重视这个jQuery的功能,所显示的新项目。是否尝试没有成功以下;

Is there a way to call a JS or jQuery function afterwards a PrimeFaces dataGrid has switched between pages and the data content has changed? I have to set a jQuery function for items that are shown on a data grid, since the items are shown page by page, i have to re-attach this jQuery function to the new items that are shown. Have tried the following with no success;

//way #1 - call ajax on complete/ on success after a page link has been clicked
$('.ui-paginator').click(function(e) {
                alert("enter");
                $.ajax({
                    success: function(data, textStatus, jqXHR) {
                        alert("success");
                        $('.certain-class').attachFunction();
                    },
                    complete: function(data, textStatus, jqXHR) {
                        alert("complete");
                        $('.certain-class').attachFunction();
                    }
                });

//way #2 - after the content of the data grid has changed, call the function 

$('.ui-datagrid-content').ajaxComplete(function() {
   alert("changed outside");
   $('.certain-class').attachFunction();
});

结果我得到的是,警报beeing称为(因此,该功能附后),但总是在DataGrid中的内容被改变之前,我想用一个超时的,但这并不是所期望的方式。

The result I'm getting is that the alerts are beeing called (so, the function is attached) but always before the content on the dataGrid is changed, I thought of using a timeout, but this is not the desired approach.

我使用PF 5.0。

推荐答案

您可以使用AJAX页面事件:

You can use an ajax page event:

<p:dataGrid>
   <p:ajax event="page" onstart="alert("ajax started");"
                        onsuccess="alert("ajax success");"
                        oncomplete="alert("ajax completed");" />
</p:dataGrid>