Reputation: 1007
I need to get the p:dataTable object. But seems like I am not able to get the p:dataTable object using the below.
<script type="text/javascript">
var table2 = document.getElementById('test2_datatable_staffs_2');
</script>
<h:form id="form1" prependId="false">
<p:dataTable id="test2_datatable_staffs_2">
Upvotes: 1
Views: 869
Reputation: 1535
You can use widgetVar
instead of id
.
<p:dataTable widgetVar="test2_datatable_staffs_2">
You can access PrimeFaces elements in JavaScript the following way:
<script type="text/javascript">
var table2 = PF('test2_datatable_staffs_2');
</script>
Give this a try and tell me if it works.
Upvotes: 1
Reputation: 503
that cause JSF put the form name before the table id
you should use
<script type="text/javascript">
var table2 = document.getElementById('form1\\:test2_datatable_staffs_2');
</script>
Upvotes: 0
Reputation: 37051
The id of the h:form
is being prepended to your p:dataTable
You can use the following code
var table2 = document.getElementById('form1:test2_datatable_staffs_2');
Or just set the prependId=false
for the h:form
and use your current code
Upvotes: 0