• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to select a row in a table from cursor position

Community Expert ,
Mar 12, 2017 Mar 12, 2017

Copy link to clipboard

Copied

Hi,

This is probably simple, but I can’t find how.

I need a snippet that will select and entire row from the location of the insertion of the cursor. Similar to the InDesign «Select Row» command.

Sorry for the newbie question.

TOPICS
Scripting

Views

712

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Mar 12, 2017 Mar 12, 2017

Hi Jean-Claude

function selectRow(s) {

    s = s || app.selection[0];

    if (!s) {

        return 'no selection';

    }

    while (s.constructor !== Cell){

        s = s.parent;

        if (s.constructor === Application) {

            return 'no cell found';

        }

    }

    s.parentRow.select();

}

selectRow();

HTH

Trevor

Votes

Translate

Translate
Guru ,
Mar 12, 2017 Mar 12, 2017

Copy link to clipboard

Copied

Hi Jean-Claude

function selectRow(s) {

    s = s || app.selection[0];

    if (!s) {

        return 'no selection';

    }

    while (s.constructor !== Cell){

        s = s.parent;

        if (s.constructor === Application) {

            return 'no cell found';

        }

    }

    s.parentRow.select();

}

selectRow();

HTH

Trevor

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 12, 2017 Mar 12, 2017

Copy link to clipboard

Copied

Thanks Trevor... That did it!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 19, 2021 Nov 19, 2021

Copy link to clipboard

Copied

Please @Trevor: Can this script modified to avoid selecting the header cell (in the same column)?

Thanks in Advance

Best
Mohammad Hasanin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

To be clear, you want to select a column, not a row, but exclude header cells? If so, try this: 

 

function selectColumn(s) {
    s = s || app.selection[0];
    if (!s) {
        return 'no selection';
    }
    while (s.constructor !== Cell){
        s = s.parent;
        if (s.constructor === Application) {
            return 'no cell found';
        }
    }
    var target = s.parentColumn;
    var pccells = target.cells;
    for (var i = 0; i < pccells.length; i++) {
        if (pccells[i].rowType !== RowTypes.HEADER_ROW) {
            pccells[i].select();
        }
    }
}

selectColumn();

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

Thanks  a lot @brian_p_dts

Best
Mohammad Hasanin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

Please @brian_p_dts  What is the Opposite Command of (Select()), i searched the DOM many times but didnt find anything, just deselect for item pages, but i mean deselect cells opposite of select();

Thanks

Best
Mohammad Hasanin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

app.selection = null will remove all selections. The select() method has optional arguments that you can pass to it to replace the existing selection (default is to add to selection). 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

Thanks a lot @brian_p_dts 

Best
Mohammad Hasanin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 26, 2024 Dec 26, 2024

Copy link to clipboard

Copied

Suppose, I don't have a table header row yet.

I am going to select multiple rows and convert them to table headers.
How do I get the rows that are currently selected with the mouse?
selectedRows =

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
6 hours ago 6 hours ago

Copy link to clipboard

Copied

LATEST

Hi @dublove 
try this :

 

 

DoConvert();       

function DoConvert(){
    var myTable = app.selection[0]; // Get the selected top cells
    var myRows = myTable.rows; // Get all table rows in selection

    // Loop through each row in the table
    for (var i = 0; i < myRows.length; i++) {
        // Check if the row is a body row and convert it to a header row
        if (myRows[i].rowType === RowTypes.BODY_ROW) {
            myRows[i].rowType = RowTypes.HEADER_ROW;
        }
    }
    alert("Body rows converted to header rows successfully.");
}

 

 

Best
Mohammad Hasanin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines