How to dynamically display new page via html

22 views
Skip to first unread message

Russell West

unread,
Jan 4, 2017, 7:25:44 PM1/4/17
to SlickGrid
As a previous post mentioned I have the dubious honor of converting an existing application which uses a JQuery Datatable implementation over to use a Slickgrid implementation.  I have run into the following issue due to a lack of knowledge with Slickgrid capabilities:

The original JQuery Datatable implementation will cause the generation/display of a new web page through the use of an html href tag when the user selects a specific bootstrap glyphicon which resides in the Actions column of each datatable row. Following is the associated javascript code snippets:

From the javascript file that renders the Datatable
      
         ....
         ....
         columns : [
                           {
                                 title: "Actions",
                                 className: "action_icons",
                                 orderable: false,
                                 render: function(data, type, row){
                                     return ( 
                                                  getActionHTML("/documents/" + row.docID, "glyphicon-new-window", "View Document Details")
                                              );
                                      },
                           },
                           {
                                data : "docCreateDate",
                                title : "Document Creation Date",
                                className : "col-date:,
                                render : function(data, type, row) {
                                                 return formattedDateText(new Date( data), "YYYY-MM-DDTHH:mm:ss");
                                            },
                                defaultContent : ""
                           },
 
                           .... other datatable column data 


                        ]

From the javascript file that generates html for display/rendering of new page

       ....
       ....
       function getActionHTML(href, icon, title, newWindow){
           if (newWindow){
                return '<a href="' + href + '"class="glyphicon ' + icon + '" title="' + title +'" target="_blank"></a>';
           }
           return '<a href="' + href + '"class="glyphicon ' + icon + '" title="' + title +'"></a>';

       }


When the bootstrap glyphicon-new-window type icon is selected from the Actions column for a specific row within the datatable the href html definition generated earlier when the datatable rows were populated is returned and used to render a new page.  Such html would look like: <a href="/documents/1000" class="glyphicon glyphicon-new-window" title="View Documents Details"></a>

I am attempting to determine the equivalent process for the Slickgrid implementation I am currently working on but have not been successful.  Any assistance would be greatly appreciated.


Bill Rebey

unread,
Jan 5, 2017, 11:53:59 AM1/5/17
to slic...@googlegroups.com

Russel, I’m not positive what exactly your issue is, but I think this fiddle shows you what you need:

 

http://jsfiddle.net/brebey/03nwsbm1/9/

 

It uses:

-          Custom formatter to produce whatever HTML you want in the target cell.  I generate an <a> tag in the example.  (Incidentally, this example would also suffice to show you how to use a custom date formatter, like the one you  use in your Datatable code, below).

-          Click handler to intercept clicks to those generated <a> tags, and prevention of default click action

-          Calling a method (like your “getActionHTML” method) using the value from the <a> tag

 

Let me know if this answers your question or not.

--
You received this message because you are subscribed to the Google Groups "SlickGrid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to slickgrid+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Russell West

unread,
Jan 5, 2017, 1:40:08 PM1/5/17
to SlickGrid
Bill thanks for your reply, but I am not sure it gets me 100% there.  After talking with a co-worker this morning we thought about the following possible solution:

In the Action Slickgrid column store the appropriate href html so that the actual bootstrap glyphicon-new-window icon would be visible and when the user selects the icon the
associated href html would be rendered displaying the new page.  The problem I have is that the generated href html needs to know the associated ID of each row and such
is not known until the data for each row is processed, so I do not believe I can call a formatter function when the columns are being defined.

To hopefully illustrate my situation:

Rough example of Slickgrid with three columns shown (@ used to depict bootstrap glyphicon-new-window icon)

         Action     Document Creation Date .....................................Document ID

            @        2017-01-01T06:00:00      .....................................1000
            @        2017-01-02T06:00:00      .....................................2000
            @        2017-01-03T06:00:00      .....................................3000


So looking at your example and including my application requirements when the user clicks on the Action icon (@) for each respective row shown the following 
html would need to be rendered to display the new page with correct associated document data:


So here are the new coding issues I am trying to resolve based on this new solution:

1) Generate the correct HTML so that the bootstrap glyphicon-new-window icon is displayed in the Action column as a link and so that the appropriate row ID is used

    I have seen the following example HTML for generating a link for a bootstrap glyphicon

        <a href="#">
          <span class="glyphicon glyphicon-new-window"></span>
        </a>

   but I am not sure how to include the needed https://documents/......

2) Store the HTML in the Slickgrid Action column so that the bootstrap glyphicon-new-window icon is visible and not the actual HTML text

I hope this makes some sense???

Thanks Again,
Russell

Bill Rebey

unread,
Jan 5, 2017, 2:03:16 PM1/5/17
to slic...@googlegroups.com

You’re  there – you just don’t know it.

 

#1

When you’re in the formatter, you’ll notice the signature is (row, cell, value, columnDef, dataContext).

 

dataContext is the row in the Data array that contains the cell you’re rendering.  Thus, if you fill in your “href” attribute with -  instead of ‘#’ – something like this, you’ll get exactly what you need – the href will be correct:

 

return   ‘<a href="https://documents/’+ dataContext[7] +’">’ +

            ‘<span class="glyphicon glyphicon-new-window"></span>’ +

‘</a>’

 

Asuming that column 7 of your data set is where your “Document ID” value is.

 

#2

That’s already what my example does.  Look at the JSFiddle from my last eMail, and run the example.  You won’t see “<a href=…..” in the cell on the screen;  you’ll see a hyperlink, whose name (the thing you can see) is the data that I put in the  text of the <a> tag.

Russell West

unread,
Jan 5, 2017, 5:23:26 PM1/5/17
to SlickGrid
Bill,

I am real close now, but I am not seeing the bootstrap glyphicon-new-window icon visible in the Action column.  I had a coding error initially and did not have the opening "<" for the span clause of the generated HTML.  So when the Slickgrid rendered you could see the text span.....  When I selected this text the appropriate new page displayed - which is great.  When I corrected this coding error, there is nothing visible in the Action column and as a result I can not select anything to display the new page.  Following are sections of code I currently executing:


           documentDetailsHTMLFormatter = function(row, cell, value, columnDef, dataContext){

                return   ‘<a href="https://documents/’+ dataContext["documentId"] +’">’ +

                           ‘<span class="glyphicon glyphicon-new-window"></span>’ +

               ‘</a>’;

]


            var columns = [
                                     checkboxSelector.getColumnDefinition(),
                                     {id:"action", name:"Action", field:"action", sortable:false, editable:false, width:50, minWidth:50, maxWidth:50, formatter:documentDetailsHTMLFormatter},
                                     .....
                                     .....
                                     {id:"documentId", name:"Document ID", field:"documentId", sortable:true, editable:false, width:150, minWidth:50, maxWidth:300}
                                  ]

            var docHitsData = [];

             $.ajax({type:"POST",
                        url: docHitsUrl,
                        data: docHitsData,
                        success: function(docHitsData){
                                          for (var hitIndex = 0; hitIndex < docHitsData.data.length; hitIndex++){
                                              var d = (docHitsData[hitIndex] = {});
                                              var hitData = docHitsData.data[hitIndex];
                                              d["id"] = "docHitsDataID_" + hitIndex;
                                              d["date"] = createFormattedDate(new Date(hitData["date"]), "YYYY-MM-DDTHH:mm:ss");
                                              ....
                                              ....
                                             d["documentId"] = hitData["documentID"];
                                          }
                                       }
                                    });


I have tried adding various versions of code to set d["action"] to different values like the string "Details" similar to your example of "Doc1.txt" but nothing seems to show up in the Action column.

Probably a stupid question but here goes anyway - In your example I notice you have the data array defined before the columns array, does such order matter since we are calling the formatter function which references the dataContext?
Just had to ask.  So I am trying to figure out why the bootstrap glyphicon-new-windo icon is not being displayed.

Bill Rebey

unread,
Jan 5, 2017, 5:33:14 PM1/5/17
to slic...@googlegroups.com

No, Russell, the order of definition of those variables shouldn’t matter.

 

If I understand the problem correctly from your description, I think you’re probably up against  a simple CSS issue.

 

Am I correct in understanding that the problem seems only to be that the hyperlink (glyph, in this case) doesn’t show up in the column in the grid, so there’s nothing to click on, and hence no way to load the page?

 

If that’s right, try this: 

1)      Remove the ‘class=”gly….” ‘ attribute from your Span.

2)      Between the now-empty open/close tags of the span, put something in there like “Link!”

3)      It’ll look like this:


    return   ‘<a href="https://documents/’+ dataContext["documentId"] +’">’ +

         ‘<span>Link!</span>’ +
         ‘</a>’;

 

When you reload the page, you should see the word “Link!” in a the cells that you’re using your HTML formatter for.

 

If that works, then you’ve just got some problem with your CSS, bootstrap, etc., which is beyond the scope of anything I can help you with here.

 

If that STILL fails, let me know, and we’ll look harder.

Russell West

unread,
Jan 6, 2017, 12:36:43 PM1/6/17
to SlickGrid
Bill,

Thanks for your help, your latest suggestion worked.  Would prefer to have the glyphicon-new-window icon displayed in the Action column to be consistent with original Datatable implementation, but if such can not be implemented then such is life.  I own you a beer or whatever your preferred alcoholic beverage is  (if any) .

Thanks again for your great help.

Russell

Bill Rebey

unread,
Jan 6, 2017, 12:45:29 PM1/6/17
to slic...@googlegroups.com

Oh, it’s beer alright!  You don’t owe me anything, though, Russel.  We’ve all gotten plenty of help from the community, and I’m happy to give back.

 

HOWEVER!  Don’t give up!  My suggestion was merely a TROUBLESHOOTING suggestion – not a solution.

 

So…it sounds like if you take your icon out of the picture, everything works and you get your link and the link works and so on, right?

 

Great!

 

That just means that the fundamental work is correct – you’re building your SlickGrid correctly, formatting the data correctly, and so on.

 

All you have to do now is figure out why your glyph won’t show up. 

 

It’s probably just some CSS thing, like it has margins or padding that make it display out-of-sight and outside the confines of the cell’s visible boundaries.

 

Or maybe it’s a resource problem, and the image file is missing.  Or maybe it’s a  CSS loading issue, and the CSS that you think is loading isn’t loading at all.

 

Definitely, though, what you’re talking about doing is NOT outside the realm of possibility.   It’s quite common.  I have built all sorts of SlickGrid applications with all sorts of icons, images, buttons, and so on inside them.  This all works fine.  You’ve just got to figure out why your glyph isn’t showing up;  it’s not a SlickGrid problem, though, for sure. 

 

Keep after it!  You’ll get it!

 

It sounds like you might not be very familiar with debugging Web applications.  If you’re not already familiar with the Web browser’s debug tools, you MUST learn.  This will very readily tell you what’s  inside that cell in the DOM, and it’ll show you the CSS applied to it, etc. 

 

FF, IE, and Chrome all have built-in debuggers, and FF has an add-in that’s my personal favorite, FireBug.

 

In any event, press F12 from your browser, and you should get a Debug window.  From there, you can inspect the DOM, click on the cell that’s supposed to have your glyph in it, and see what CSS is applied and so on. 

 

Good luck!

Russell West

unread,
Jan 6, 2017, 1:07:44 PM1/6/17
to SlickGrid
Bill,

Being stubborn I tried one more thing and was able to get the bootstrap icon to appear in the Action column as a link.  The following HTML works:

'<a href="/documents/' + dataContext["documentId"] + '">' +
'<i class="glyphicon glyphicon-new-window" title="View Document Details"></i>' +
'</a>';

Added the image (i) tag.

Again thanks for all your help you saved me at least a couple days of frustration figuring out the solution on my own.

Russell
Reply all
Reply to author
Forward
0 new messages