• 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

697

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

LATEST

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