简体   繁体   English

来自链接的jqgrid和弹出模式窗口

[英]jqgrid and popup modal windows from link

I have got a jqgrid, and i would like to put a link in it to open up more details on the row in a modal window. 我有一个jqgrid,我想在其中放置一个链接,以打开模态窗口中行的更多详细信息。

Everything i have read about modal windows uses a div that gets shown when you click the link, but i want to pass an id so i can just get the info i need. 我读过的关于模态窗口的所有内容都使用了一个div,当你点击链接时会显示,但我想传递一个id,这样我就能得到我需要的信息。 I know i could do it with a new window quite easly but i would like to use a modal window if poss. 我知道我可以很容易地使用一个新窗口,但我想使用模态窗口,如果可能的话。

Any ideas how i could do this. 任何想法我怎么能做到这一点。 I'm using asp.net if thats going to be relevent. 我正在使用asp.net,如果那将是相关的。

Cheers Luke 干杯卢克

I'd suggest using the jQuery UI Dialog plugin for custom modal windows. 我建议使用jQuery UI Dialog插件来自定义模态窗口。 You can find demonstration and documentation here: 您可以在此处找到演示和文档:

http://jqueryui.com/demos/dialog/ http://jqueryui.com/demos/dialog/

In theory, to do what you're asking for, you could follow these steps: 从理论上讲,为了满足您的需求,您可以按照以下步骤操作:

  1. Add a “dialog” div tag to your page. 在页面中添加“dialog”div标签。

  2. Build the link into your data feed. 构建数据源链接。 If you're using a XML data type make sure you use a CDATA flag to encapsulate your link so that they XML may be parsed correctly. 如果您使用的是XML数据类型,请确保使用CDATA标志来封装链接,以便可以正确解析XML。

    < cell>< ![CDATA[< a href=”javascript:showDialog('551')”>text]]>< /cell> <cell> <![CDATA [<a href =“javascript:showDialog('551')”> text]]> </ cell>

    In this instance, since we know the actual id at the time the link is create, I pre-populated the id (eg 551) in the function. 在这种情况下,由于我们知道链接创建时的实际ID,因此我预先填充了函数中的id(例如551)。 This could also be retrieved from jqGrid API with the selrow property. 这也可以使用selrow属性从jqGrid API中检索。 It's your call. 这是你的电话。 If you use a JSON data type, the idea would similar. 如果您使用JSON数据类型,那么这个想法就会类似。 You wouldn't have to worry about the CDATA qualifier. 您不必担心CDATA限定符。

  3. Create a local function (eg showDialog (id)) to correspond to your link. 创建一个本地函数(例如showDialog (id))以对应您的链接。
  4. Add code in the showDialog function to populate and open the modal dialog. showDialog函数中添加代码以填充并打开模式对话框。 Using an AJAX call to gather specific data for this record, create the dialog content and populate the dialog using the jQuery .html method. 使用AJAX调用收集此记录的特定数据,创建对话框内容并使用jQuery .html方法填充对话框。

    function showDialog (id) { function showDialog(id){

    $.ajax({ url: "feed.aspx?id=" + id, success: function(data) { var content = // TODO: create dialog layout here $ .ajax({url:“feed.aspx?id =”+ id,success:function(data){var content = // TODO:在这里创建对话框布局

      $("#dialog").html(content); $("#dialog").dialog({ title: 'Record Details', modal: true, closeOnEscape: true, width: 300, height: 200, buttons: false, position: "center", }); $("#dialog").dialog("open"); } 

    }); }); } }

This is just one way to skin the cat. 这只是给猫皮肤的一种方法。 You should be able to use more of a jQuery approach with the link creation. 您应该能够在创建链接时使用更多jQuery方法。 If desired, rather than building the specific link the data feed, you could add jQuery click event bindings to handle the request. 如果需要,您可以添加jQuery单击事件绑定来处理请求,而不是构建数据源的特定链接。 It's your call. 这是你的电话。 You could also add the dialog div dynamically to your page using jQuery rather than just placing it manually like I described above. 你也可以使用jQuery动态地将对话框div添加到你的页面,而不是像我上面描述的那样手动放置它。 It might be a little more elegant looking but would achieve the same goal. 它可能看起来更优雅,但会达到同样的目标。

I am attempting this late. 我这么晚才尝试。 May be you have an answer. 可能你有答案。 Thought this will help others. 认为这将有助于其他人。

The #dialog code can be done as suggested by gurun8. #dialog代码可以按照gurun8的建议完成。 This needs to be wired to the jqgrid. 这需要连接到jqgrid。 There is a onSelectRow event which triggers whenever a row is selected in jqgrid. 有一个onSelectRow事件,只要在jqgrid中选择了一行,就会触发该事件。 Refer documentation . 参考文档 I usually add autoOpen: false , to the dialog constructor. 我通常将autoOpen: false添加到对话框构造函数中。

You need to add the onselectrow event to the grid (jqgrid function as shown below) and you can pass the id to the function. 您需要将onselectrow事件添加到网格(jqgrid函数,如下所示),您可以将id传递给函数。 This id is the unique identifier in the jqgrid. 此id是jqgrid中的唯一标识符。 Make sure there are no syntax errors, add comma wherever appropriate. 确保没有语法错误,在适当的地方添加逗号。

$s("#list").jqGrid({
...
  onSelectRow: function(id){
    console.log("row is selected"+id);
    $url = "your_url/";
    $s('#dialog').load($url);
    $s('#dialog').dialog('open');
  }
...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM