Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8551993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:19:19+00:00 2026-06-11T14:19:19+00:00

I want to know how do I get a column selection I have the

  • 0

I want to know how do I get a column selection

I have the following datatable

<p:dataTable id="DataTable" value="#{dataTable.selecDataModel}" var="test" scrollable="TRUE" scrollHeight="500" styleClass="day-column2" selectionMode="single" >
    <p:column headerText="Column1" footerText="Column1" width="450">
        <h:outputText value="Test1" />
    </p:column>
    <p:column headerText="Column2" footerText="Column2" width="450">
        <h:outputText value="Test2" />
    </p:column>
 </p:dataTable>

The p:ajax only support row selection, if I would like to know which column is selected, how do I get the same.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:19:20+00:00Added an answer on June 11, 2026 at 2:19 pm

    You can find out the index of the selected column with jQuery and send it to server as an ajax event

    here is a way:

    first add an inputText above the table (make it hidden)

    <h:inputText id="mySelectedColumnId" value="#{myBean.mySelectedColumnField}" style="display:none">
        <f:ajax listener="#{myBean.myListener}"></f:ajax>
    </h:inputText>
    

    and the following js code to bind clicking on the table and triggering click on the h:inputText which will trigger listened on the server

    jQuery(document).delegate("#yourTableID td", "click", function (event) {//bind every click on any td in the table
        var columnNumber = jQuery(this).index();//get index of clicked row
        jQuery("#mySelectedColumnId").val(columnNumber); //set value in the inputtext
        jQuery("#mySelectedColumnId").change(); //this will trigger the ajax listener
    });
    

    Update

    What I actually meant was the following structure:

    <h:outputScript name="js/newjavascriptfile.js" target="head" />
    
    .
    .
    .
    .
    
    <h:form prependId="false">
         <h:inputText id="mySelectedColumnId" value="#{myBean.mySelectedColumnField}" style="display:none">
             <f:ajax listener="#{myBean.myListener}"></f:ajax>
         </h:inputText>
         <p:dataTable id="DataTable"....
    .
    .
    .
    .
    

    and inside the js (place it inside js folder inside resources folder in the root of your web app folder Resources (Library) In JSF 2.0) file place

    jQuery(window).load(function () {
         jQuery(document).delegate("#yourTableID td", "click", function (event) {//bind every click on any td in the table
            var columnNumber = jQuery(this).index();//get index of clicked row
            jQuery("#mySelectedColumnId").val(columnNumber); //set value in the inputtext
            jQuery("#mySelectedColumnId").change(); //this will trigger the ajax listener
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to know how to get all column value from table using sphinx
I just want to know how to get column value of one of my
i want know if is possible, to get a specific element value of a
I want to run the following rename EXECUTE sp_rename N'dbo.Semesters.IsPublic', N'Tmp_ShowNCs', 'COLUMN' I get
I have an EXTJS paging grid with checkbox selection model. I want to know
I want to know how to get the value of the selected rawquery Cursor
I want to know how can we get the column name from the table
I have a JTable . I want to know which row and column are
I want to know how to get client IP address using jQuery? Is it
I want to know how to get the cursor position on Windows in c++,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.