Jump to content
UBot Underground

Convert Table to HTML view?


Recommended Posts

Hi.

 

I'm looking for a way to format the content of a table into good looking  HTML code.

So that I can show it in the ubot browser via load HTML.

 

 

The html table code could be like:

<table border="2" bordercolor="F91E1E" style="background-color:EFEFEF" width="450" cellpadding="5" cellspacing="5">
<tr>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
</tr>
<tr>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
</tr>
<tr>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
</tr>
</table>
 
 
I'm looking for a define that is able to generate that HTML code dynamically depending on the amount of rows / columns in a table.
 
Maybe someone has done something like that already? if not, I will start working on it.
 
Cheers
Dan
Link to post
Share on other sites

schau mal ob dir das was taugt schon lange nicht mehr benutzt...

 

plugin command("Open.Framework_new.dll", "Structure Container", "JSON LIST") {
    clear list(%jsonlist)
    add list to list(%jsonlist, $list from text(#TABLE or LIST, $new line), "Don\'t Delete", "Local")
    clear list(%json_columnnames)
    add list to list(%json_columnnames, $list from text(#COLUMNNAMES, ","), "Don\'t Delete", "Global")
    clear list(%JSONLISTclean)
    set(#JSON recid name, "recid:", "Global")
    set(#JSON recid counter, 1, "Global")
    comment("HIER WERDEN DIE DATENSÄTZE ZUSAMMEN GEBAUT")
    loop($list total(%jsonlist)) {
        set(#list_record, $next list item(%jsonlist), "Global")
        clear list(%list_record)
        add list to list(%list_record, $list from text(#list_record, #SEPARATOR), "Don\'t Delete", "Local")
        set(#list_record_total, $list total(%list_record), "Global")
        set(#list_record_total_counter, 0, "Global")
        set(#jsonval, "\{{#JSON recid name} {#JSON recid counter},", "Global")
        set(#jsonval counter, 0, "Global")
        loop($list total(%list_record)) {
            set(#item, $list item(%list_record, #jsonval counter), "Global")
            if($comparison(#list_record_total, "=", #list_record_total_counter)) {
                then {
                }
                else {
                    set(#jsonval, "{#jsonval}f{$change text casing($list item(%json_columnnames, #jsonval counter), "Lower Case")}: \"{#item}\", ", "Global")
                }
            }
            increment(#jsonval counter)
            increment(#list_record_total_counter)
        }
        set(#jsonval, "{#jsonval}\},", "Global")
        set(#jsonval, $replace(#jsonval, ", \}", "\}"), "Global")
        set(#jsonval, $replace(#jsonval, ",\}", "\}"), "Global")
        add item to list(%JSONLISTclean, #jsonval, "Don\'t Delete", "Global")
        set list position(%list_record, 0)
        increment(#JSON recid counter)
    }
    clear list(%jsonlist)
    clear list(%list_record)
    clear list(%json_tmp)
    set list position(%json_columnnames, 0)
    set(#jsonsize, $divide(100, $list total(%json_columnnames)), "Global")
    set(#jsonsize, "{#jsonsize}%", "Global")
    comment("HIER WERDEN DIE  COLUMNS GEBAUT")
    set(#jsonval, "\{ field: 'recid', caption: 'ID', size: '50px', sortable: true \},", "Global")
    add item to list(%json_tmp, #jsonval, "Don\'t Delete", "Global")
    loop($list total(%json_columnnames)) {
        set(#json_col, $next list item(%json_columnnames), "Global")
        set(#jsonval, "\{field: 'f{$change text casing(#json_col, "Lower Case")}', caption: '{#json_col}', size:'{#jsonsize}',sortable: true, resizable: true, editable: \{ type: 'text' \}\},", "Global")
        add item to list(%json_tmp, #jsonval, "Don\'t Delete", "Global")
        set(#jsearch, "\{field: \'f{$change text casing(#json_col, "Lower Case")}\', caption: \'{#json_col}\', type:\'text\'\},", "Global")
        add item to list(%jsearch, #jsearch, "Delete", "Global")
    }
    set(#jsonval, %json_tmp, "Global")
    set(#jsearch, %jsearch, "Global")
    set(#jsonrec, %JSONLISTclean, "Global")
    set(#jsonval, "name: \'grid\', 
show: \{ 
	toolbar: true,
	footer: true,
	toolbarAdd: true,
	toolbarDelete: true,
	toolbarSave: true,
	fixedBody: false,
\},

toolbar: \{
	onClick: function (target, data) \{console.log(target)\}
\},

searches: [

{#jsearch}

	],
sortData: [\{ field: \'recid\', direction: \'ASC\' \}],


columns: [

		{#jsonval}

	],


records:[

		{#jsonrec}

	]", "Global")
    set(#JSONTEMPLATE, "<!DOCTYPE HTML>
<html>
<head>
<meta charset=\"utf-8\">
<script src=\"http://skapps.webhop.net/incl/w2ui/jquery.min.js\"></script>
<script src=\"http://code.jquery.com/ui/1.10.3/jquery-ui.js\"></script>
<script src=\"http://skapps.webhop.net/incl/w2ui/w2ui-1.2.js\"></script>
<link rel=\"stylesheet\" href=\"http://skapps.webhop.net/incl/w2ui/w2ui-1.2.css\" />
</head>
<body>
<div id=\"MyList\"></div>
<script>
$(function ()\{
	$(\'#MyList\').w2grid(\{
{#jsonval}
	\});

var winheight = $(window).height();
$(\'#MyList\').css(\'height\', winheight-20);
document.title = \'My List\';

\});

</script>
</body>
</html>
", "Global")
    set(#jsonrec, $nothing, "Global")
    set(#jsonval, $nothing, "Global")
    clear list(%JSONLISTclean)
}

Link to post
Share on other sites

if you have my sqlite plugin you can use table to html function

I have that one. It's realy nice. The problem I have with that is, that it doesn't add any borders around the table cells. 

So it's a little bit hard for users to see what belongs to what.

 

would that be something you could add Aymen?

 

Dan

Link to post
Share on other sites

Ok, I wrote a short function to convert a table into a HTML table.

You can change the look and feel of the table by just changing the html table options in the last "load html" command:

 

define CreateTable {
    set(#tableHtml$nothing"Global")
    set(#RowPosition, 0, "Global")
    loop($table total rows(&reportingdata)) {
        set(#tableHtml"{#tableHtml}
<tr>""Global")
        set(#Cellposition, 0, "Global")
        loop($table total columns(&reportingdata)) {
            set(#tableHtml"{#tableHtml}
<td>{$table cell(&reportingdata#RowPosition#Cellposition)}</td>""Global")
            increment(#Cellposition)
        }
        set(#tableHtml"{#tableHtml}
</tr>""Global")
        increment(#RowPosition)
    }
    load html("<table border=\"2\" bordercolor=\"F91E1E\" style=\"background-color:EFEFEF\" width=\"450\" cellpadding=\"5\" cellspacing=\"5\">
{#tableHtml}
</table>        ")
}

 

 

 

Cheers

Dan

Edited by dan
  • Like 3
Link to post
Share on other sites
  • 2 weeks later...
  • 7 months later...

Ok, I wrote a short function to convert a table into a HTML table.

You can change the look and feel of the table by just changing the html table options in the last "load html" command:

 

define CreateTable {

    set(#tableHtml$nothing"Global")

    set(#RowPosition, 0, "Global")

    loop($table total rows(&reportingdata)) {

        set(#tableHtml"{#tableHtml}

<tr>""Global")

        set(#Cellposition, 0, "Global")

        loop($table total columns(&reportingdata)) {

            set(#tableHtml"{#tableHtml}

<td>{$table cell(&reportingdata#RowPosition#Cellposition)}</td>""Global")

            increment(#Cellposition)

        }

        set(#tableHtml"{#tableHtml}

</tr>""Global")

        increment(#RowPosition)

    }

    load html("<table border=\"2\" bordercolor=\"F91E1E\" style=\"background-color:EFEFEF\" width=\"450\" cellpadding=\"5\" cellspacing=\"5\">

{#tableHtml}

</table>        ")

}

 

 

 

Cheers

Dan

Very handy Dan - Thanks for that.

Link to post
Share on other sites
  • 1 year later...

schau mal ob dir das was taugt schon lange nicht mehr benutzt...

 

 

plugin command("Open.Framework_new.dll", "Structure Container", "JSON LIST") {
    clear list(%jsonlist)
    add list to list(%jsonlist, $list from text(#TABLE or LIST, $new line), "Don\'t Delete", "Local")
    clear list(%json_columnnames)
    add list to list(%json_columnnames, $list from text(#COLUMNNAMES, ","), "Don\'t Delete", "Global")
    clear list(%JSONLISTclean)
    set(#JSON recid name, "recid:", "Global")
    set(#JSON recid counter, 1, "Global")
    comment("HIER WERDEN DIE DATENSÄTZE ZUSAMMEN GEBAUT")
    loop($list total(%jsonlist)) {
        set(#list_record, $next list item(%jsonlist), "Global")
        clear list(%list_record)
        add list to list(%list_record, $list from text(#list_record, #SEPARATOR), "Don\'t Delete", "Local")
        set(#list_record_total, $list total(%list_record), "Global")
        set(#list_record_total_counter, 0, "Global")
        set(#jsonval, "\{{#JSON recid name} {#JSON recid counter},", "Global")
        set(#jsonval counter, 0, "Global")
        loop($list total(%list_record)) {
            set(#item, $list item(%list_record, #jsonval counter), "Global")
            if($comparison(#list_record_total, "=", #list_record_total_counter)) {
                then {
                }
                else {
                    set(#jsonval, "{#jsonval}f{$change text casing($list item(%json_columnnames, #jsonval counter), "Lower Case")}: \"{#item}\", ", "Global")
                }
            }
            increment(#jsonval counter)
            increment(#list_record_total_counter)
        }
        set(#jsonval, "{#jsonval}\},", "Global")
        set(#jsonval, $replace(#jsonval, ", \}", "\}"), "Global")
        set(#jsonval, $replace(#jsonval, ",\}", "\}"), "Global")
        add item to list(%JSONLISTclean, #jsonval, "Don\'t Delete", "Global")
        set list position(%list_record, 0)
        increment(#JSON recid counter)
    }
    clear list(%jsonlist)
    clear list(%list_record)
    clear list(%json_tmp)
    set list position(%json_columnnames, 0)
    set(#jsonsize, $divide(100, $list total(%json_columnnames)), "Global")
    set(#jsonsize, "{#jsonsize}%", "Global")
    comment("HIER WERDEN DIE  COLUMNS GEBAUT")
    set(#jsonval, "\{ field: 'recid', caption: 'ID', size: '50px', sortable: true \},", "Global")
    add item to list(%json_tmp, #jsonval, "Don\'t Delete", "Global")
    loop($list total(%json_columnnames)) {
        set(#json_col, $next list item(%json_columnnames), "Global")
        set(#jsonval, "\{field: 'f{$change text casing(#json_col, "Lower Case")}', caption: '{#json_col}', size:'{#jsonsize}',sortable: true, resizable: true, editable: \{ type: 'text' \}\},", "Global")
        add item to list(%json_tmp, #jsonval, "Don\'t Delete", "Global")
        set(#jsearch, "\{field: \'f{$change text casing(#json_col, "Lower Case")}\', caption: \'{#json_col}\', type:\'text\'\},", "Global")
        add item to list(%jsearch, #jsearch, "Delete", "Global")
    }
    set(#jsonval, %json_tmp, "Global")
    set(#jsearch, %jsearch, "Global")
    set(#jsonrec, %JSONLISTclean, "Global")
    set(#jsonval, "name: \'grid\', 
show: \{ 
	toolbar: true,
	footer: true,
	toolbarAdd: true,
	toolbarDelete: true,
	toolbarSave: true,
	fixedBody: false,
\},

toolbar: \{
	onClick: function (target, data) \{console.log(target)\}
\},

searches: [

{#jsearch}

	],
sortData: [\{ field: \'recid\', direction: \'ASC\' \}],


columns: [

		{#jsonval}

	],


records:[

		{#jsonrec}

	]", "Global")
    set(#JSONTEMPLATE, "<!DOCTYPE HTML>
<html>
<head>
<meta charset=\"utf-8\">
<script src=\"http://skapps.webhop.net/incl/w2ui/jquery.min.js\"></script>
<script src=\"http://code.jquery.com/ui/1.10.3/jquery-ui.js\"></script>
<script src=\"http://skapps.webhop.net/incl/w2ui/w2ui-1.2.js\"></script>
<link rel=\"stylesheet\" href=\"http://skapps.webhop.net/incl/w2ui/w2ui-1.2.css\" />
</head>
<body>
<div id=\"MyList\"></div>
<script>
$(function ()\{
	$(\'#MyList\').w2grid(\{
{#jsonval}
	\});

var winheight = $(window).height();
$(\'#MyList\').css(\'height\', winheight-20);
document.title = \'My List\';

\});

</script>
</body>
</html>
", "Global")
    set(#jsonrec, $nothing, "Global")
    set(#jsonval, $nothing, "Global")
    clear list(%JSONLISTclean)
}

 

I know that this is a bit old, but what is it about?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...