about checkbox

127 views
Skip to first unread message

tuch...@gmail.com

unread,
Mar 18, 2008, 12:57:28 AM3/18/08
to JMesa
hello! i am a chinese developer.
and i has a problem about the worksheet's checkbox.
when i want to select the all checkbox of current page.i have to
select checkbox one by one.
i think this is a not good way. so i want to know that was there a
easy way to select all checkbox of current page.
example:
in firstRow(the title row),i add a specified checkbox,when i
select this checkbox,the other checkboxs of current page all checked.

that's all,i hope you understand what i mean. i am not very good at
English ^_^.
i very like the JMesa Table.

Jasen

unread,
Mar 18, 2008, 6:51:48 AM3/18/08
to JMesa
put a check box as the title...type the title code as this:
title="<input type=checkbox onclick=\"for( i=0 ;
i<this.form.elements.length ; i++){if
(this.form.elements[i].name=='idArray')
{this.form.elements[i].checked=this.checked;}}\"/>"


喜欢JMesa 就多玩玩,大庭广众喊得那么激烈多不好意思呀...
Jasen Hsu




On Mar 18, 12:57 pm, "tuchun...@gmail.com" <tuchun...@gmail.com>
wrote:

Renato Back

unread,
Mar 18, 2008, 12:41:52 PM3/18/08
to jm...@googlegroups.com
One other way woud be to implement a HeaderEditor to include a checkbox on the header.
There's a sample one attached to this message.
To use it, just add the following to your class that uses tableFacade:

// Name of the column that has the checkbox
String idColumnName = "A name";
// Defines if the table will start with all elements checked or not
boolean selectAll = true;
// Get the html table.
HtmlTable htmlTable = (HtmlTable) tableFacade.getTable();
// Get the Id column, meaning the one which has the checkboxes
HtmlColumn idColumn = htmlTable.getRow().getColumn(idColumnName);
// Add the header editor to create the checkbox and add the onclick behavior
idColumn.getHeaderRenderer().setHeaderEditor(new SelectHeaderEditor(idColumnName, selectAll));
// Add the checkboxes to the other cells on the id column
idColumn.getCellRenderer().setCellEditor(new SelectCellEditor(selectAll));

Oh, by the way, you need to add a javascript function to your page. Here's the sample idea:
function selectAllItens(tid) {
    var table        = document.getElementById(tid);
    var inputs      = table.getElementsByTagName("input");
    var inputOption = inputs[0];
    //begin on 1 to ignore the header checkbox and count only the other ones on the table
    for (var i = 1; i < inputs.length; i++)      {
        inputs[i].checked = inputOption.checked;
    }   
}


It works for me, so I hope it meets your expectations.

Cheers,

Renato Back

2008/3/18, Jasen <jasen....@gmail.com>:
SelectHeaderEditor.java
SelectCellEditor.java

tuch...@gmail.com

unread,
Mar 18, 2008, 11:15:15 PM3/18/08
to JMesa

Thank you Jasen and Renato Back for your reply.
your ideas is works good. but in Worksheet,there are some problems
following:

1.In worksheet ervery cell has a onclick even like this:
onclick="var up = {};up['id']='75004';createWsColumn(this,
tableid,up,propertyName)"
so if i used SelectCellEditor to create checkbox in other cells,when
i click the cell the even onclick will be called.
That is not i need.So i used CheckboxWorksheetEditor to create
checkbox in toher cells,and it also used in JMesa's WorkSheet example
like this:
column.getCellRenderer().setWorksheetEditor(new
CheckboxWorksheetEditor());

2.In worksheet every checkbox has a onclick even too,like this:
<input type="checkbox" onclick="var up =
{};up['id']='75004';submitWsCheckboxColumn(this,tableid,up,property)" /
>
and this onclick even just be called when i click the checkbox(not
the head checkbox).
When this even was be called,the ajax request will be submited,and
the worksheet's state will be saved.
When i go to the nextpage then return ,the state will be restored.
But when i click the head checkbox ,even though the other checkbox
were all checked,but the onclick even was not called.
So the wordsheet's state will not be saved,when i go nextpage then
return,the state will be lost.
So in Renato Back's javascript code i insert one line code to call
the "submitWsCheckboxColumn" manually.like this:

function selectAllItens(tid) {
var table = document.getElementById(tid);
var inputs = table.getElementsByTagName("input");
var inputOption = inputs[0];
//begin on 1 to ignore the header checkbox and count only the
other ones on the table
for (var i = 1; i < inputs.length; i++){
inputs[i].checked = inputOption.checked;
//call the "submitWsCheckboxColumn" manually
inputs[i].onclick();
}
}


And now ,my problem was resolved.
Thack you again.
> 2008/3/18, Jasen <jasen.hsu...@gmail.com>:
>
>
>
>
>
> > put a check box as the title...type the title code as this:
> > title="<input type=checkbox onclick=\"for( i=0 ;
> > i<this.form.elements.length ; i++){if
> > (this.form.elements[i].name=='idArray')
> > {this.form.elements[i].checked=this.checked;}}\"/>"
>
> > 喜欢JMesa 就多玩玩,大庭广众喊得那么激烈多不好意思呀...
> > Jasen Hsu
>
> > On Mar 18, 12:57 pm, "tuchun...@gmail.com" <tuchun...@gmail.com>
> > wrote:
>
> > > hello! i am a chinese developer.
> > > and i has a problem about the worksheet's checkbox.
> > > when i want to select the all checkbox of current page.i have to
> > > select checkbox one by one.
> > > i think this is a not good way. so i want to know that was there a
> > > easy way to select all checkbox of current page.
> > > example:
> > > in firstRow(the title row),i add a specified checkbox,when i
> > > select this checkbox,the other checkboxs of current page all checked.
>
> > > that's all,i hope you understand what i mean. i am not very good at
> > > English ^_^.
> > > i very like the JMesa Table.
>
>
>
> SelectHeaderEditor.java
> 1KDownload
>
> SelectCellEditor.java
> 1KDownload- Hide quoted text -
>
> - Show quoted text -

Jeff Johnston

unread,
Mar 18, 2008, 11:29:52 PM3/18/08
to JMesa

I wrote up an issue ticket to include this functionality in the API!

I was also wondering if you could tell me your experience so far with
working with the worksheet? Are things working like you expect? Was
the documentation clear enough?

-Jeff Johnston



On Mar 18, 10:15 pm, "tuchun...@gmail.com" <tuchun...@gmail.com>
wrote:

Kyle

unread,
Apr 7, 2008, 9:33:21 AM4/7/08
to JMesa
It will be wonderful to have this 'select/deselect all' function as a
built-in feature for 'tableFacade' tag.
something like:
<jmesa:tableFacade id="tag" items="${presidents}" var="bean"
editable="true" selector="true">
Reply all
Reply to author
Forward
0 new messages