cancel
Showing results for 
Search instead for 
Did you mean: 

Check TableView Row Selection in Javascript

Former Member
0 Kudos

Hi everyone,

I am trying to check in my javascript code if a row has been selected in my tableview. I looked at the discussion in the following thread:

I tried to use some of the methods suggested by in that thread but it doesn't seem to be working correctly.

Here is my javascript code:

function warn(){

var funcName = htmlb_formid+"_getHtmlbElementId";

func = window[funcName];

var table = eval(func("tblCalendarList"));

if(table.getSelectedRow() != null) {

var confirmed = window.confirm("You are about to permanently delete this record. To continue press OK");

if(confirmed){

document.all.<%=buttonDelete%>.click();

}

else {

htmlbevent.cancelSubmit = true;

}

}

}

The code is supposed to check if a row is selected. If a row is selected, the code should through a warning message. In case no row is selected, the code should just continue submitting the form without throwing any messages.

I am not sure that I am correctly retrieving the tableview object.

Currently the code table.getSelectedRow() returns null whether or not a row is actually selected.

Accepted Solutions (0)

Answers (1)

Answers (1)

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi Qasem,

Try to validate your tableview using this way.

<%@ taglib uri="tagLib" prefix="hbj" %>

<%@ page import="com.sapportals.htmlb.table.TableViewModel"%>

<SCRIPT language="javascript">

var flag = false;

function setFlag()

{

flag = true;

}

function checkFlag()

{

if(flag == false)

{

alert("Pls select a row!!");

htmlbevent.cancelSubmit="true";

return false;

}

}

</SCRIPT>

<jsp:useBean id="Bean" scope="application" class="com.suresh.kb" />

<hbj:content id="myContext" >

<hbj:page title="PageTitle">

<hbj:form id="myFormId" >

<hbj:tableView id="myTableView"

design = "ALTERNATING"

headerVisible = "true"

footerVisible = "true"

fillUpEmptyRows = "true"

navigationMode = "BYLINE"

selectionMode = "SINGLESELECT"

headerText = "Selection"

onNavigate = "onNavigation"

visibleFirstRow = "<%= Bean.getVisibleRow() %>"

visibleRowCount = "2" >

<% myTableView.setModel(Bean.getModel()); %>

<% myTableView.setOnClientRowSelection("setFlag()"); %>

<% myTableView.setJsObjectNeeded(true); %>

</hbj:tableView>

<hbj:button id="submit"

text="Details!"

tooltip="Click me to get detail"

disabled="false"

onClick="DetailPressed"

onClientClick="checkFlag()"

jsObjectNeeded = "TRUE"

design="emphasized" />

</hbj:form>

</hbj:page>

</hbj:content>

Former Member
0 Kudos

Thanks Suresh for your answer...I haven't tried it yet but I think it will help me a work around.

What I wanted to do is be able to access the tableview object from within the javascript code so that I can call methods such as getSelectedRow() and getSelectedRowKey()

If you know how to access the tableview object from within javascript, I would really appreciate. The idea of providing sample code works great for me.