次の方法で共有


Extending CQWP with Toolpart- Adding functionality like PageFilter, Pagination - Part 2

This is continuation of earlier post.

CQWP does not have the PageFilter and Pagination functionatilies. By extendign the CQWP, It can be achieved through the XSLT. Pagination is very often used feature for the content displaying webpart.

Pagination

We saw how can we use "ProcessDataDelegate" in the earlier one. By using the same functiontionality we have to achieve the pagination and it should be compatible with XSLT.  ProcessDataDelegate pass resultset of CQWP as the DataTable.

1) Add a column "No" in to DataTable and assign the number for earch row.

2) By using the RowFilter we can filter the row from the starting number to end number what we want. Below is the logic to achieve this.

 int currentPage = 1;
 this.pagesCount = (int)Math.Ceiling((double)dt.Rows.Count / this.ItemsPerPage);

 int startItemNumber = (currentPage - 1) * this.ItemsPerPage;

 int endItemNumber = startItemNumber + (this.ItemsPerPage - 1);
 dt.Columns.Add("Number", typeof(int));

 for (int i = 0; i < dt.Rows.Count; i++)
{

dt.Rows[i]["Number"] = i;

}

dt.DefaultView.RowFilter = String.Format(CultureInfo.CurrentCulture, "Number >= {0} AND Number <= {1}", startItemNumber, endItemNumber);

 dt = dt.DefaultView.ToTable();

 return dt;

 Above logic will return the filtered DataTable

3) How to display in XSLTBy using ModifyXsltArgumentList method we have to add one more parameter
 "argList.AddParameter("PaginationString", string.Empty, pagingHTML)"
4) we have declear a string varibale pagingHTML and coin the HTML to display the pages 
 i.e By using  "builderHtml.Append("<a href=\"#\">" + paginationPrevious + "</a>");"
5) After it should be passed to xslt parameter as mentioned above.

PageFilter

PageFilter functionality will be used when you are provisioning a page with particular field and based on the field value CQWP should filter the data. Again by extending the ProcessDataDelegate, we can achieve this.

1) Add to dropdown into Editor webpart

2)  Display  the current page content type field in first dropdown display, and current site fields in next dropdown

3) Bring the values in to DataProcessing delegate

4) Fetch the value like below

                SPField sourceField = SPContext.Current.Item.Fields.GetFieldByInternalName(this.PageFilterField);
                SPField targetField = SPContext.Current.Site.RootWeb.Fields.GetFieldByInternalName(this.TargetFilterField);

5) Compage the value  and filter it from DataTable.

Happy coding..