2

I need to create a list containing some data. Also, for each set of records I have one or more records each. Is it possible to achieve using a single list ? I need to save the whole thing in a one single click. How can we do that? Can we use a list inside another list ?

EDIT

I want to create FAQ sections for a portal. There may be a number of FAQ sections where each contains a set of questions & answers. I need to do it without writing code. Is it possible with sharepoint native features ?

2

A sharepoint list within another list of Sharepoint not, but the second list can be built dynamically using JavaScript and JSON.

You create the HTML elements (Table with inputs) in the forms of its parent list. Then you would use JavaScript to get the information to the user put in the inputs, this information puts you in a JavaScript object.

Transform the object into a JSON string (Example) and store the string in the parent list column. Whenever the user opens a form, you check the column that has the information of the sub list is empty, if it is not, transform JSON to object again (Example) and build the sub list of column values with JavaScript.

So you would have a sub list within the parent list. I've used this solution to a list control budgets where budget items were dynamically constructed.

Update

Inputs that the user uses to add or delete information.
The HTML Inputs

My code HTML:

            <table border="0" cellspacing="0" width="100%" id="itensUM">
                <tr>
                    <td colspan="4">
                        <h2 style="padding:20px 0">
                            Itens do Orçamento
                        </h2>
                    </td>
                </tr>
                <tr>
                    <th>
                        <h4>
                            Nome
                        </h4>
                    </th>
                    <th>
                        <h4>
                            Quantidade
                        </h4>
                    </th>
                    <th>
                        <h4>
                            Preço
                        </h4>
                    </th>
                </tr>
                <tr class="controleItens" id="ItensTR">
                    <td>
                        <input type="text" value="" id="nomeItem"></input>
                    </td>
                    <td>
                        <input type="text" value="" id="qtdItem"></input>
                    </td>
                    <td>
                        <input type="text" value="" id="precoItem"></input>
                    </td>
                    <td>
                        <img width="20" src="../../SiteAssets/IMG/add.png" onclick="constuirItem()"></img>
                    </td>
                </tr>
            </table>

Then use a JavaScript function when the user clicks "+", this function adds new rows to table with the information he put in inputs. My function:

    function constuirItem(){
        var nomeItem = $('#nomeItem').val();
        var qtdItem = $('#qtdItem').val();
        var precoItem = $('#precoItem').val();

        $('#nomeItem').val('');
        $('#qtdItem').val('');
        $('#precoItem').val('');
        cont++;
        $('#itensUM').append('<tr class="controleItens" id="ItensTR'+cont+'">'+
                                '<td>'+
                                    '<input type="text" id="nomeItem'+cont+'" readonly="readonly" value="'+nomeItem+'"></input>'+
                                '</td>'+
                                '<td>'+
                                    '<input type="text" id="qtdItem'+cont+'" readonly="readonly" value="'+qtdItem+'"></input>'+
                                '</td>'+
                                '<td>'+
                                    '<input type="text" id="precoItem'+cont+'" readonly="readonly" value="'+precoItem+'"></input>'+
                                '</td>'+
                                '<td>'+
                                    '<img width="20" src="../../SiteAssets/IMG/delete.png" id="btnDelete'+cont+'" onclick="deleteItem(btnDelete'+cont+', false)"></img>'+
                                '</td>'+
                             '</tr>');

        $('#ItensTR'+cont).data('cont', cont);
    }

Ready you have already built the table visually. Then do each in a class to get and put the values ​​in an object. Note that I used ".date" to put the value of the cont in the tr, then I get to this value and knowing the id's of the inputs, so I can get their values​​.

You put the values ​​in an object and the object in an array, then transforms the array of objects in a JSON string. After all that saves the JSON into a column of type "Multiple lines of text" like this:

$('.controleItens').each(function() {
    var cont = $(this).data('cont');    
    var nome = $('#nomeItem'+cont).val();
    var qtd = $('#qtdItem'+cont).val();
    var preco = $('#precoItem'+cont).val();

    var OBJitens = {
        Nome: nome,
        Quantidade: qtd,
        Preco: preco,
    }

    if(nome != '' || qtd != '' || preco != ''){
        //console.log(OBJitens);
        ARRitens.push(OBJitens);
    }
});

This "each" put the object in array. Now transformed into a JSON and store in a column, like this:

var JSONItens = JSON.stringify(ARRitens);
$('textarea[title="Resumo Itens"]').val(JSONItens);

The part of "each" and transformation, I always do the "pre-save action.". Ready saved you a list within another list, to rebuild just turns into a JSON object again and distribute the values ​​in a HTML table. Use this to transform the JSON object again:

var ARRitens = JSON.parse($('textarea[title="Resumo Itens"]').val());

(Hope that helps, is the most complete answer I can give you. If it helps, please mark as answer.)

  • 1
    Is it possible to do it using sharepoint native features ? (without writing code ?) – Anish V Jan 7 '14 at 3:32
  • You will have to write HTML, CSS and JQuery codes. Nothing too difficult. – Diego Hillesheim Jan 7 '14 at 10:46
  • native is no possible :( – Diego Hillesheim Jan 7 '14 at 10:49
  • ok. Can you provide a sample or link for the same ? – Anish V Jan 7 '14 at 11:51
  • I've implemented some solutions so I can provide you pieces of my code and explain what it does in a few minutes I will introduce the code in my answer – Diego Hillesheim Jan 7 '14 at 11:57
0

No, you can't have list within a list but you can use two separate lists within the same site and link one to the each other using a Lookup column type

  • Thanks for your reply. For using the lookup, we need to save the main list first, rt ? I want to save both list in one click. Is it possible ? – Anish V Jan 6 '14 at 12:57
  • I wonder if you're saving it programatically? What type of records you have? – Falak Mahmood Jan 6 '14 at 13:06
  • I want to create FAQ sections for a portal. There may be a number of FAQ sections where each contains a set of questions. I need to do it without writing code. Is it possible with sharepoint native features ? – Anish V Jan 7 '14 at 3:31
  • FAQ is nothing more than a bunch of questions with their answers and be done with native features. You can create a custom list to hold questions and answers. Create a separate list to hold FAQ sections like section 1 2 3 or so on and refer FAQ section ID as look up column in questions and answers (custom list). See example thechriskent.com/2012/03/09/simple-sharepoint-faq-in-5-minutes – Falak Mahmood Jan 7 '14 at 4:32
  • ok. Is it possible to create a FAQ section and add the relevant questions/answers and save everything in one go ? – Anish V Jan 7 '14 at 5:10
0

Use a standard list and have a Group/Section column which is a choice field. Then group the list view according to the Group/Section. No need for coding a solution here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.