You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Webix DataTable中TBD列URL点击功能实现求助

如何让Webix表格中的URL列变为可点击链接?

嗨,我来帮你搞定这个问题!要让Webix表格里的URL变成可点击的链接,其实只需要给对应的列添加一个自定义模板,把纯文本URL转换成HTML锚点标签就行,具体操作如下:

解决方案步骤

Webix的datatable默认会把单元格内容当作纯文本渲染,我们可以通过template属性自定义单元格的HTML结构,从而生成可点击的链接。

1. 修改表格列的配置

找到你代码中columns数组里的linkjournal列,添加template属性,用函数来动态渲染链接:

{ 
    id:"linkjournal", 
    header:["TBD"], 
    width:220, 
    sort:"string",
    template: function(obj){
        // 两种显示方式可选:
        // 方式1:直接显示URL作为链接文本
        return `<a href="${obj.linkjournal}" target="_blank">${obj.linkjournal}</a>`;
        // 方式2:显示自定义文本(比如"打开TBD页面")
        // return `<a href="${obj.linkjournal}" target="_blank">打开TBD页面</a>`;
    }
}

2. 完整修改后的Webix代码片段

替换后你的表格配置会变成这样:

webix.ready(function(){
    grid = webix.ui({
        container:"testA",
        view:"datatable",
        columns:[
            { id:"index", header:"TA", sort:"int"},
            { id:"ac", header:["CT", {content:"selectFilter"}],width:120, sort:"string"},
            { id:"ad", header:["Date", {content:"textFilter"}] , width:120, sort:"int"},
            { id:"ads", header:["Arcid", {content:"textFilter"}], width:100, sort:"string"},
            { id:"eob", header:["Pl", {content:"textFilter"}], width:100, sort:"string"},
            { 
                id:"linkjournal", 
                header:["TBD"], 
                width:220, 
                sort:"string",
                template: function(obj){
                    return `<a href="${obj.linkjournal}" target="_blank">${obj.linkjournal}</a>`;
                }
            }
        ],
        autoheight:true,
        autowidth:true,
        data:small_film_set2,
        on:{
            "data->onStoreUpdated":function(){
                this.data.each(function(obj, i){
                    obj.index = i+1;
                })
            }
        }
    });
});

额外说明

  • template函数的obj参数代表当前行的所有数据,所以我们能直接拿到obj.linkjournal里的URL值。
  • target="_blank"是让链接在新浏览器窗口打开,如果你想在当前窗口打开,可以去掉这个属性。
  • 另外注意下你PHP代码里的$adep变量:当前代码里只定义了$ad = $row["day"];,但URL里用的是$adep,可能是笔误,建议确认下这个变量的赋值是否正确,避免生成无效链接。

内容的提问来源于stack exchange,提问作者Flora8832

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 10:07:35