Showing posts with label Apps. Show all posts
Showing posts with label Apps. Show all posts

Saturday, December 8, 2012

SharePoint 2013 - Create a search app

It is not hard to create an App for search to use search javascript.

The search REST service is at http://site/_api/search/query?querytext='querytext'

In the app, need to add search permission,
 
In the default app page, the following html elements are defined.
<div id="toolbarDiv">
 
<input type="text" id="queryTerms" />
<button onclick="executeQuery($get('queryTerms').value); return false;">Search</button>
</div>
 
 
And here is the example script to send the query text to search service and display the results.

function executeQuery(queryTerms) {
    Results = {
        element: '',
        url: '',
        init: function (element) {
            Results.element = element;
            Results.url = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?querytext='" + queryTerms + "'";
        },
        load: function () {
            $.ajax({
                url: Results.url,
                method: "GET",
                headers: { "ACCEPT": "application/json" },
                success: Results.onSuccess,
                error: Results.onError
            });
        },
        onError: function (error) { alert(JSON.stringify(error)); },
        onSuccess: function (data) {
            var results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
            var html = "<table>";
            for (var i = 0; i < results.length; i++) {
                html += "<tr><td>";
                html += results[i].Cells.results[3].Value;
                html += "</td><td>";
                html += results[i].Cells.results[6].Value;
                html += "</td></tr>";
                }
            html += "</table>";
            Results.element.html(html);
        }
    }
    Results.init($('#resultsDiv'));
    Results.load();
       
}

Tuesday, November 20, 2012

SharePoint 2013 Apps is an opportunity

Now SharePoint 2013 is out. Since the beta version with the new Apps programming model, I have talked to many developers. Like what I first see this, most of them are disappointed. Apps is not something the SharePoint developers really want, it moves to another direction rather than giving us something better and easier for SharePoint server solutions development.

My opionion about this actually has been changed. I think SharePoint team is on the right track and we need to embrace this model. Since SharePoint 2007, all the versions were built on top of asp.net. And in these years, web development has been changed so much because of the the power of javascript library. In MVC4, you have all the good javascript library included in the box to do amazing things that give very good user experience.

Since SharePoint 2013 has a good revamp in their client javascript library, developers finally can do things like the modern web apps can do. So now SharePoint developers have the tools in hand and can work with them in SharePoint 2013. I believe it is time to leave your comfortable zone and start to write your own mordern web apps within SharePoint.