Working on How to Show Different Views of SharePoint Lists into Page by ID in SharePoint Hosted Apps

1) Create a view of the list.

createview

2) Open Schema.xml file, the code should look like

<View BaseViewID=”2″ Name=”715f4146-f6ae-4cfb-bca8-9d09d6ad4ba1″ DisplayName=”CustomView”   DefaultView=”TRUE” MobileView=”TRUE” MobileDefaultView=”FALSE” Type=”HTML” WebPartZoneID=”Main” SetupPath=”pages\viewpage.aspx” Url=”CustomView.aspx”>

   <Toolbar Type=”Standard” />

   <XslLink Default=”TRUE”>main.xsl</XslLink>

   <JSLink>clienttemplates.js</JSLink>

   <RowLimit>3</RowLimit>

   <ViewFields>

          <FieldRef Name=”EmployeeName” />

          <FieldRef Name=”FromDate” />

          <FieldRef Name=”ToDate” />

          <FieldRef Name=”No_x002e_OfLeave_x0028_s_x0029_” />

   </ViewFields>

   <Query />

   <Toolbar Type=”Standard” />

   <XslLink Default=”TRUE”>main.xsl</XslLink>

 </View>

3) Add new Client Web Part by right click on project -> Add new item, then select “Client Web Part (Host Web)” template under Office/SharePoint category.

4) In the next wizard, make your choice by either selecting “Create a new client web part page” or even can usedefault.aspx page, based on your requirements.

5) If you have selected the new web part page in the previous section then it will create a new page in the Pages folder.

6) If you want to use a master page in that page then make change accordingly like replace HTML section with content placeholders, add master page URL in page directive etc.

If not using master then you have to add below control in page.

<WebPartPages:SPWebPartManager ID=”SPWebPartManager2″ runat=”Server” />

7) Now add below code for WebPartZone in the same page, irrespective of using master page or not.

<WebPartPages:AllowFraming ID=”AllowFraming” runat=”server” />

       <WebPartPages:WebPartZone runat=”server” FrameType=”TitleBarOnly” ID=”Right”Title=”loc:full”>

           <ZoneTemplate></ZoneTemplate>

</WebPartPages:WebPartZone>

8) Open Elements.xml file under Pages module/folder and add new module.

<Module>

    <File Path=”Pages\Leave_Request.aspx” Url=”Pages/Leave_Request.aspx”Type=”GhostableInLibrary”>

      <View List=”Lists/LeaveRequest” BaseViewID=”2″ WebPartZoneID=”Right” WebPartOrder=”1″>

        <!CDATA>

      </View>

    </File>

  </Module>

In above code:

Path attribute in File tag: it should be your aspx file path.

Url attribute in File tag: it should be aspx file URL, the difference is of ‘\’ & ‘/’.

List attribute in View tag: the list name with URL ‘Lists/[List name]’

BaseViewID: this is the ID which you have specified for View in Schema.xml of the list. This id should match with BaseViewID in schema.xml file.

I have followed this instruction to show view based on BaseViewID, but it not showing my view as per id, it only shows a view which has been set as the default view, so currently trying to find out the solution.