bittersour
bittersour

Reputation: 1007

How to get p:dataTable id

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

Answers (3)

LarsBauer
LarsBauer

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

Omar NourdeaN
Omar NourdeaN

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

Daniel
Daniel

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

Related Questions