简体   繁体   中英

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">

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

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM