Search This Blog

Friday, November 3, 2017

Sharepoint Accordin view in customList

<link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<div class="panel-group" id="accordion" style="padding-top:15px">
</div>
<script>

$(function () {
    setdata();
    $("#accordion-1").accordion({
        heightStyle: "Content",
        collapsible: true
    });
});

function setdata() {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', loadAccordianData);
}
   
 
function loadAccordianData() 
{
    var clientcontext = new SP.ClientContext();
    var web = clientcontext.get_web();
    var list = web.get_lists().getByTitle('AccordionList');
    listitems = list.getItems(SP.CamlQuery.createAllItemsQuery());
    clientcontext.load(listitems);
    clientcontext.executeQueryAsync(success, onQueryFailed);
   
}
function success() {
    //Get the  values     
    var c = 0;
    var listitemenumerator = listitems.getEnumerator();
    while (listitemenumerator.moveNext()) {
        var oItem = listitemenumerator.get_current();
        var headerContent = oItem.get_item('Title');
        var bodyContent = oItem.get_item('Description')
        c = c + 1;
        var stringVal = "<div class='panel panel-default'><div class='panel-heading'><h4 class='panel-title'><a data-toggle='collapse' data-parent='#accordion' href='#collapse" + c + "'>" + headerContent + "</a></h4></div><div id='collapse" + c + "' class='panel-collapse collapse in'><div class='panel-body'>" + bodyContent + "</div></div></div>";
        $('#accordion').append(stringVal);
    }
}
 
function onQueryFailed(sender, args) 
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
 </script>


No comments:

Post a Comment