Select to view content in your preferred language

Link button field in Dojo DataGrid

4992
3
03-19-2013 02:16 AM
VishakhaDubey
Deactivated User
I am trying to retrieve data from a table related to the rest map service I am using in my application, which is successfuly being retrieved, the problem I am facing is that I have a link field associated with each record in the table which opens a pdf file. I want to create a column containing link buttons for each record which on click opens the pdf related with that particular record. Please suggest me how can I do this.
0 Kudos
3 Replies
EmilyLaMunyon
Deactivated User
Hi,
I think I understand what you are trying to accomplish. The way I created a link to a pdf in my table is this. In my JavaScript code:
function makeLink(name){
 
 var link =  "<a target='_blank' href='http://someurl/map/map_search/sire_survey_image.cfc?&page_id=" + name[0] + "'>PDF</a>";

 return link;

 }

and in the html that creates the table:
<th fields="page_id" formatter="makeLink"width="100px" > 


Hope that helps!
0 Kudos
VishakhaDubey
Deactivated User
Thank you for your suggestion. But I have already tried this method. I cannot provide the url in the href attribute manually, as I have to get it from a related table on feature selection. Although I am able to get the url and now I am using window.open() function to open that pdf, but the problem occuring is that it is only working on onRowClick event of the grid. And as I have two pdf links fields in my grid both the pdf files gets open simultaneously.
Also my main page gets reloaded once the link is clicked.
Can you suggest something for this.
0 Kudos
DavideLimosani
Frequent Contributor
try using this layout for your datagrid:
           layout = [
                [
                    {name: 'FirstCol', field: '0', width: '80px'},
                    {name: 'SecondCol', field: '1', width: '80px'},
                    {
                        name: " ",
                        field: '2',
                        width: '80px',
                        formatter: function (value) {
                            return new dijit.form.Button({label: "OpenPDF", onClick: function () {
                               // your stuff depending on value
                            } })

                        }
                    }
                ]
            ];




if you get your data from your map service populate your datagrid in this way:
            dataForGrid = [];

            for (var key in mapServiceResponse.items) {
              
                dataForGrid.push([mapServiceResponse.items[key].firstField, responseAttivita.items[key].secondField, mapServiceResponse.items[key].objectid]);

// the third parameter is the value you get in your third column formatter

            }

            data1 = {
                items: dataForGrid
            };

            store = new dojo.data.ItemFileReadStore({
                data: data1
            });


grid = new dojox.grid.DataGrid({
                    store: store,
                    structure: layout,
                    rowSelector: '20px'},
                document.createElement('div'));
0 Kudos