Jump to content

Does it possible to directly (without files) print UniDbGrid?


Tokay

Recommended Posts

20 minutes ago, Tokay said:

Does it possible to directly (without files) print UniDbGrid?

Hello, You can use Print: https://www.w3schools.com/jsref/met_win_print.asp#:~:text=The print() method prints,to select preferred printing options.

to "The print() method prints the contents of the current window."

maybe @Sherzod will help to select only grid like here:

https://www.aspsnippets.com/Articles/Print-HTML-Table-using-JavaScript.aspx

or https://stackoverflow.com/questions/21375398/how-to-print-table-using-javascript

 

Link to comment
Share on other sites

Tokay , 
<script type="text/javascript">
    function PrintTable() {
        var printWindow = window.open('', '', 'height=200,width=400');
        printWindow.document.write('<html><head><title>Table Contents</title>');
 
        //Print the Table CSS.
        var table_style = document.getElementById("table_style").innerHTML;
        printWindow.document.write('<style type = "text/css">');
        printWindow.document.write(table_style);
        printWindow.document.write('</style>');
        printWindow.document.write('</head>');
 
        //Print the DIV contents i.e. the HTML Table.
        printWindow.document.write('<body>');
        var divContents = document.getElementById("dvContents").innerHTML;
        printWindow.document.write(divContents);
        printWindow.document.write('</body>');
 
        printWindow.document.write('</html>');
        printWindow.document.close();
        printWindow.print();
    }
</script>
Link to comment
Share on other sites

3 minutes ago, Tokay said:

Thank you. It works but not perfectly.

When I've try open printing then just empty page is shown:

image.png.bcdb0e28f3ceba33fa4559c4b17fa06d.png

But after closing this preview with cancel button, and push ctrl+p printing looks as expected:

image.thumb.png.540e87ea89ffee8375459dd376fb3efd.png

Except of temporary data on the back.

Yes, that's true.

@Sherzod could help here, hopefully now that I understand what you're looking for.


There are other issues, but this is some kind of start.

 

Link to comment
Share on other sites

8 minutes ago, Tokay said:

Except of temporary data on the back.

You must replace here with Your data:

        //Get the Table CSS from theme css style.
        + ' printWindow.document.write(''<script src="/ext-7.0.0/build/ext-all.js"></script>'');'

//You must replace here with Your theme

        + ' printWindow.document.write(''<link rel="stylesheet" href="/ext-7.0.0/build/classic/theme-classic/resources/theme-classic-all.css">'');'
        + ' printWindow.document.write(''<script src="/ext-7.0.0/build/classic/theme-classic/theme-classic.js"></script>'');'
//You must replace here with Your version of uniGui

        + ' printWindow.document.write(''<script src="/uni-1.90.0.1537/ext-unicommon-min.js"></script>'');'
        + ' printWindow.document.write(''<script src="/uni-1.90.0.1537/ext-sync-min.js"></script>'');'
        + ' printWindow.document.write(''<script src="/uni-1.90.0.1537/jQuery/jquery-1.11.2.min.js"></script>'');'
        + ' printWindow.document.write(''<link rel="stylesheet" href="/uni-1.90.0.1537/css/uni-xtheme-common.css">'');'
        + ' printWindow.document.write(''<link rel="stylesheet" href="/uni-1.90.0.1537/css/uni-ext.css">'');'
        + ' printWindow.document.write(''<link rel="stylesheet" href="/uni-1.90.0.1537/css/uni-xtheme-classic.css">'');'

Link to comment
Share on other sites

1 hour ago, Tokay said:

Now it works better, thank you very much!

Here is my best code ;)

Grid - Exporter.zip

I am also sharing the code here:

procedure TMainForm.UniButton2Click(Sender: TObject);
begin
uniVersion := UniServerModule.UniGUIVersion;
uniTheme := UniMainModule.Theme;
UniSession.AddJS('let printWindow;'
        + ' function PrintTable() {'
//        + ' var printWindow = window.open('''', ''My Table direct Print'', ''height=200,width=400'');'
        //Show on new browser tab
        + ' printWindow = window.open('''', '''', '''');'
        + ' var table_sName = document.getElementById("' + UniDBGrid1.JSId + '_header-title-textEl").innerHTML;'
        + ' printWindow.document.write(''<html><head>'');'
        //Get Table title
        + ' printWindow.document.write(''<title>'');'
        + ' printWindow.document.write(table_sName);'
        + ' printWindow.document.write(''</title>'');'
        //Get the Table CSS from package.
        + ' printWindow.document.write(''<script src="/ext-7.0.0/build/ext-all.js"></script>'');'
        //Get the Table CSS from theme css style.
        + ' printWindow.document.write(''<script src="/ext-7.0.0/build/' + uniTheme + '/theme-classic/theme-classic.js"></script>'');'
        + ' printWindow.document.write(''<link rel="stylesheet" href="/ext-7.0.0/build/' + uniTheme + '/theme-classic/resources/theme-classic-all.css">'');'
        //Get the Table CSS from uniGui Version css style.
        + ' printWindow.document.write(''<script src="/' + uniVersion + '/ext-unicommon-min.js"></script>'');'
        + ' printWindow.document.write(''<script src="/' + uniVersion + '/ext-sync-min.js"></script>'');'
        + ' printWindow.document.write(''<script src="/' + uniVersion + '/jQuery/jquery-1.11.2.min.js"></script>'');'
        + ' printWindow.document.write(''<link rel="stylesheet" href="/' + uniVersion + '/css/uni-xtheme-common.css">'');'
        + ' printWindow.document.write(''<link rel="stylesheet" href="/' + uniVersion + '/css/uni-ext.css">'');'
        + ' printWindow.document.write(''<link rel="stylesheet" href="/' + uniVersion + '/css/uni-xtheme-classic.css">'');'
        //Print the Table CSS.
        + ' var table_style = document.getElementById("' + UniDBGrid1.JSId + '").innerHTML;'
        + ' printWindow.document.write(''<style type = "text/css">'');'
//        + ' printWindow.document.write(''<style type = "text/css">'');'
//        + ' printWindow.document.write(table_style);'
        + ' printWindow.document.write(''</style>'');'
        + ' printWindow.document.write(''</head>'');'

        //Print the DIV contents i.e. the HTML Table.
        + ' printWindow.document.write(''<body>'');'
        //this is with best result of new window
        + ' var divContents = document.getElementById("' + UniDBGrid1.JSId + '-bodyWrap").innerHTML;'
//        + ' var divContents = document.getElementById("' + UniDBGrid1.JSId + '-body").innerHTML;'
//        + ' var divContents = document.getElementById("' + UniDBGrid1.JSId + '").innerHTML;'
        + ' printWindow.document.write(divContents);'
        //show table on all screen place
        // ??????
        + ' printWindow.document.write(''</body>'');'

        + ' printWindow.document.write(''</html>

  • Upvote 1
Link to comment
Share on other sites

Good solution, but You don't need to suck the data from the HTML table, but rather take it directly from the db as you build the JS code.

This is how I do it, build the JS code on the fly with data using direct access db components. It is faster than referencing the DOM.

Link to comment
Share on other sites

7 hours ago, Ron said:

but rather take it directly from the db as you build the JS code

This needs to communicate with the server, my solution aims to print the data from the screen. But you are right, the best solution is to create a print preview with some components designed for this. I think there were several threads about this on the forum

Link to comment
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.

×
×
  • Create New...