jQuery UI Widgets Forums Grid Tricky hyperlink in grid idea

This topic contains 3 replies, has 2 voices, and was last updated by  jscoder 9 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Tricky hyperlink in grid idea #68251

    jscoder
    Participant

    Hello,

    I am trying to create hyperlink in the grid even followed following link but my case is little tricky.Hope someone could guide me to accomplish
    http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/customcolumn.htm?classic

    My xml is like,

    <products>
    <product docid="XXX123">
    <productname>ABC</productname>
    ....
    </product>
    </products>

    My grid code,

    var getAdapter = function () 
       {
                var source =
                {
                    datatype: "xml",
                    datafields: [
                    { name: 'productname', type: 'string' }
                    ],
                    root: "products",
                    record: "product",
                    id: "docid",
                    url: url
                };
    	var dataAdapter = new $.jqx.dataAdapter(source);
                    return dataAdapter;
          }

    I want “productname” column should be hyperlink and hyperlink uses “docid” in url for reference. I found following code in reference but this returns the productname not the docid.

    var linkrenderer = function (row, column, value) {
    	        alert(value);
                    var format = { target: '"_blank"' };
                    var html = $.jqx.dataFormat.formatlink("http://www.google.com?id="+value, format);
                    return html;
                }

    Could someone please assist me on this ?

    Thanks !

    Tricky hyperlink in grid idea #68257

    Dimitar
    Participant

    Hello jscoder,

    You would have to load the data from docid, too, to be able to access it. The following examples shows how to load data from XML attributes: http://www.jqwidgets.com/community/topic/binding-datatable-to-xml-attribute/#post-48916.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Tricky hyperlink in grid idea #68275

    jscoder
    Participant

    Thanks Dimitar! Do you mean to accomplish hyperlink I need to redesign my XML file completely ? ain’t it possible to accomplish this using my existing schema ? Could you please provide sample example to hyperlink first column with your suggested schema ?

    Thanks a ton!

    Tricky hyperlink in grid idea #68311

    jscoder
    Participant

    Aha got it done. Thanks Dimitar. Here is the solution if someone interested.

    Decided to keep same xml file format,

    <products>
    <product docid="XXX123">
    <productname>ABC</productname>
    ....
    </product>
    </products>

    Added id in datafields,

      datafields: [
                    { name: 'docid', type: 'string' },
                    { name: 'productname', type: 'string' },
                    ],
    /* Create JQGrid */
                $("#jqxgrid").jqxGrid(
                {
                    width: 850,
                    source: getAdapter(),
                    pageable: true,
    	sortable: true,
                    groupable: true,
    	autoheight: true,
                    filterable: false,
    	autoshowfiltericon: false,
                    columnsresize: true,
                    altrows: true,
                    columns: [
    	{ text: 'Product Name', datafield: 'productname',cellsrenderer: Opendocument},
                         ....
                    ]
                });

    Renderer function,

    var Opendocument= function (id,row, column, value) {
                    var _id= $('#jqxgrid').jqxGrid('getcellvalue', id, "docid");
    	var _pname=$('#jqxgrid').jqxGrid('getcellvalue', id, "productname");
                    var format = { target: '"_new"' };
    	var href="<a href=/$path/"+_id+"?OpenDocument>"+_pname;
                    var html = $.jqx.dataFormat.formatlink(href, format);
                    return html;
     }
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.