Tokay Posted September 6, 2022 Share Posted September 6, 2022 Does it possible to directly (without files) print UniDbGrid? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 6, 2022 Share Posted September 6, 2022 3 minutes ago, Tokay said: to directly (without files) print ? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 6, 2022 Share Posted September 6, 2022 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 Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 6, 2022 Share Posted September 6, 2022 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> from here: https://www.aspsnippets.com/Articles/Print-HTML-Table-using-JavaScript.aspx Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 6, 2022 Share Posted September 6, 2022 I have try to create example, based on this above link, but I need help from @Sherzod to get data from grid 1. My form with print button 2. this is result 3. here is the code if You ask for that Grid - Exporter.zip Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 6, 2022 Share Posted September 6, 2022 @irigsoft Perhaps the question is different. Print directly... Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 6, 2022 Share Posted September 6, 2022 11 minutes ago, Sherzod said: @irigsoft Perhaps the question is different. Print directly... yes, maybe. Can You tell me how to get dbgrid style from my example, please ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 6, 2022 Share Posted September 6, 2022 6 minutes ago, irigsoft said: Can You tell me how to get dbgrid style from my example, please ? I will try to check. 1 Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 6, 2022 Share Posted September 6, 2022 2 minutes ago, Sherzod said: I will try to check. i have attach a file with my code, if that can save time. Quote Link to comment Share on other sites More sharing options...
Tokay Posted September 6, 2022 Author Share Posted September 6, 2022 5 hours ago, Sherzod said: ? Directly to printer, without usign of any files Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 6, 2022 Share Posted September 6, 2022 1 minute ago, Tokay said: Directly to printer, without usign of any files hello, try my code: Grid - Exporter.zip Quote Link to comment Share on other sites More sharing options...
Tokay Posted September 6, 2022 Author Share Posted September 6, 2022 Thank you. It works but not perfectly. When I've try open printing then just empty page is shown: But after closing this preview with cancel button, and push ctrl+p printing looks as expected: Except of temporary data on the back. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 6, 2022 Share Posted September 6, 2022 3 minutes ago, Tokay said: Thank you. It works but not perfectly. When I've try open printing then just empty page is shown: But after closing this preview with cancel button, and push ctrl+p printing looks as expected: 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. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 6, 2022 Share Posted September 6, 2022 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">'');' Quote Link to comment Share on other sites More sharing options...
Tokay Posted September 6, 2022 Author Share Posted September 6, 2022 Now it works better, thank you very much! Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 6, 2022 Share Posted September 6, 2022 3 minutes ago, Tokay said: Now it works better, thank you very much! You should try it in the development version because I think there is a problem when you try to print (created a new window) the session closes. Here Scherzod I hope will help Quote Link to comment Share on other sites More sharing options...
rencarnacion Posted September 6, 2022 Share Posted September 6, 2022 You can Use QZ tray To print direct in at the local printer https://demo.qz.io/ Check it out Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 6, 2022 Share Posted September 6, 2022 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> 1 Quote Link to comment Share on other sites More sharing options...
Ron Posted September 6, 2022 Share Posted September 6, 2022 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. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 7, 2022 Share Posted September 7, 2022 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.