Stump the Panel » Site Managers and Site Collection Managers

Detect Content Type Using Javascript

(3 posts)
  • Started 4 months ago by erugalatha
  • Latest reply from erugalatha
  1. erugalatha
    Member

    Hi,

    Does anyone know if it's possible to detect the content type of a list item using javascript?

    Reason: I have 2 Data View Web Parts on a page both showing items from the same list but with 2 different content types. I want to create a menu item on the dropdown for only one of the content types.

    Posted 4 months ago #
  2. To answer your question, yes I think it's possible:
    http://darrenjohnstone.net/2008/07/22/examples-for-the-sharepoint-and-office-live-javascript-api/

    However, I don't think you need to do that. Your DVWP can already access the content type. If you use the content type variable in the XSL but add it to the web part so it doesn't render, you can easily filter your rendered items.

    For example, wrap your items in a span or div with the attribute class="MyContentType". Now you can manipulate those elements with CSS or javascript.

    Posted 4 months ago #
  3. erugalatha
    Member

    Thanks for replying.

    I will try it with XSL.

    Do you know if it's possible to get the Data View Web Part to display the Custom Actions normally? (same as the List Form Web Part does). If the Data View Web Part would display same items on its dropdown as the List Form Web Part then there would be no need for this javascript hacking.

    Steps to recreate the issue i am seeing:

    1. In Internet Explorer open SharePoint.
    2. Open any List and navigate to the AllItems.aspx view.
    3. Dropdown the menu on any list item and you should see all menu items that you have permissions to see. e.g. Manage Permissions, Workflows, View Item, Edit Item etc.
    4. In SharePoint Designer open normal AllItems.aspx View from the same list you opened above.
    5. Right-click on the List Form Web Part.
    6. Choose Convert to XSLT Data View from the resulting context menu.
    7. Save your modifications as a new view.
    8. Navigate to that view in Internet Explorer.
    9. Dropdown the menu on any item in the list.
    10. Note that only 4 menu items appear. i.e. View Item, Edit Item, Delete Item, Alert Me.

    What the deuce? :o The DVWP doesn't show menu items that you have permissions to see.

    Posted 4 months ago #

RSS feed for this topic

Reply

You must log in to post.