Select to view content in your preferred language

Printing Queried Tables

280
0
12-20-2023 06:09 AM
ranico
by
New Contributor II

I was wondering if it's possible to print out queried tables using ESRI's print widget or REST api. My application needs to query a table based on a census tract selection and only print out the data pertaining to the individual tract. I tried loading a nonspatial table into the map, enabling the 'includeTables' property in the print template and running the print function but only the map and map elements were printed, not the queried table.

Can someone verify if this is possible or help me diagnose the problem in my code? I'm not sure why the tables are not being included in the layout.

Thank you very much in advance.


        const template = new PrintTemplate({
          format: "pdf",
          exportOptions: {
            dpi: 300
          },
          layout: "a4-portrait",
          includeTables: true,
          forceFeatureAttributes: true,
          layoutOptions: {
            titleText: "Printing Demo",
            authorText: "NA"
          }
        });

        const print_params = new PrintParameters({
          view: view,
          template: template
        });

        // print when this function is called
        function executePrint() {
          print.execute(print_url, print_params).then(printResult).catch(printError);
        }

        function printResult(result) {
          console.log("template", template);
          console.log(result.url);
        }

        function printError(err) {
          console.log("Something broke: ", err);
        }
       
        // Executes the print map function
        document.getElementById('printMap').onclick = function(){
          getTract();
        }

        let nonspatialTable = null;

        function getTract(){
          const query = new Query();
          query.where = "GEOID = 36081049202";
          query.returnGeometry = false;
          query.outFields = ["GEOID","STATE","CNTY_FIPS","COUNTYNAME"];

          layer_section8BB.queryFeatures(query).then(function(response){
             
              nonspatialTable = new FeatureLayer({
                source: response.features,  // autocast as a Collection of new Graphic()
                objectIdField: "ObjectID",
                title: "Nonspatial table"
              });

              // table must be loaded so it can be used in the app.
              nonspatialTable.load().then(function() {
                // table is loaded. ready to be queried.

                map.tables.add(nonspatialTable);
                executePrint();
              });
          });
        }
0 Kudos
0 Replies