开发者

SharePoint Add New Item Button on Home Page

开发者 https://www.devze.com 2023-01-18 15:34 出处:网络
I\'m building a bulletin board site (in 2010) and I\'m sure this must be simple but again it doesn\'t seem so.Anyway on my default page I have a query webpart showing the latest items an开发者_如何学G

I'm building a bulletin board site (in 2010) and I'm sure this must be simple but again it doesn't seem so. Anyway on my default page I have a query webpart showing the latest items an开发者_如何学God what I need is just a button at the top of the page "Add new item" which would show the popup and allow users to complete the form just like it works on the display list items form.

I've looked at AllItems.aspx but can't even see the "Add new item" button to copy!

Any ideas?

Thanks

Dan


This is actually very easy. You need to know the address for your NewForm.aspx page. To make it look like a dialog box, you want to add IsDlg=1 to the query string. SharePoint has a built in JavaScript that can do all this for you. Below is an example of a button I created to open new help desk tickets.

//Handle the DialogCallback callback
function DialogCallback(dialogResult, returnValue){}

//Open the Dialog
function OpenNewDialog(){
  var options = {
    url:"/depts/is/helpdesk/Lists/Service%20Requests/NewForm.aspx?IsDlg=1",
    width: 700,
    height: 700,
    dialogReturnValueCallback: DialogCallback
  };
  SP.UI.ModalDialog.showModalDialog(options);
}

You can also leave off the width and height options and the dialog window will size itself. For the HTML

<div style="text-align: center">
   <a href="javascript:OpenNewServiceRequest()">Open a new Service Request</a>
</div>


How complicated is your query? If the query is only pulling from one list, you could put the filters into a view in the list and replace your query webpart with a List View Web Part (in the browser, select the webpart named after your list). In the List View Web Part properties, switch to your new view. By default, a List View Web Part includes an Add New Item link.

Now, it's a link and not a button. And it's in the footer of the webpart, not at the the top. If you really need a button at the top of the page, you could add a Content Editor Web Part and insert HTML for your own button. You should be able to reuse the Add New Item URL from AllItems.aspx. The URL should look something like this: http://mysite/_layouts/listform.aspx?PageType=8&ListId={21AA3D96-75EE-45CC-A153-D0FA7856DE67}&RootFolder=

0

精彩评论

暂无评论...
验证码 换一张
取 消