Data not getting displayed in the table

Data not getting displayed in the table

JanurajJanuraj Posts: 13Questions: 3Answers: 0
edited August 2 in Free community support

I am using datatables. I have collection with models as rowViews in it. How should i pass the collection to datatables, so that the data gets rendered in the table

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 2,650Questions: 21Answers: 302

    Please provide a link to your page, or to a test case demonstrating the issue.
    https://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read#latest

  • JanurajJanuraj Posts: 13Questions: 3Answers: 0
    edited August 2

    @tangerine and @allan can u please help me here, not understanding how to use ajax .
    I have the collection in my hand and not able to pass it to the datatable. I am appending the rowViews

    datatableDefault["serverSide"] = true;
    datatableDefault["ajax"] = {
    "url": baseurl
    "data": function ( d ) {
    delete d.columns;
    return d;

                },
                "dataSrc": function(d){
    
                    // that.renderList();
                    that.list = new ListCollection(d.data);
                    return d.data;
    
                },
                // success : function ( d ) {
                //    
                // },
        };
    

    renderList: function(){
    this.clearAllRowViews();
    this.list.api().clear();
    if(this.collection.length > 0){
    this.collection.forEach(this.appendRowWithoutDraw, this);
    }
    appendRowWithoutDraw: function(model, index){
    this.appendRow(model, {drawTable: false, index: index});
    },
    appendRow: function(model, options){
    var rowView = this.createRow(model, options.index);
    this.rowViews.push(rowView);
    if(!!options && options.drawTable === false){
    this.list.api().row.add(rowView.render().el);
    } else {
    this.list.api().row.add(rowView.render().el).draw();
    }
    },

    Not understanding how to implement server side, since i already have all the data in the collection. i want to render using serverside

  • JanurajJanuraj Posts: 13Questions: 3Answers: 0
    edited August 3

    @allan or anyone can u please look into this and help me understand how to do it

  • allanallan Posts: 52,268Questions: 1Answers: 7,958 Site admin
    Answer ✓

    First thing I would suggest is to remove the serverSide option (unless you are handling 50’000 or more rows of data) as it will just make things more complicated.

    Next, have your server-side script return the data from the database in JSON. If you aren’t sure how to do that, have a look on StackOverflow and similar.

    Finally, once you have the JSON data, DataTables will be able to consume that. If you aren’t sure how to do that, post a sample of the JSON the server is returning here and we’ll help you configure your DataTable.

    Allan

  • JanurajJanuraj Posts: 13Questions: 3Answers: 0

    @allan thanks for your reply, we will use json structure

Sign In or Register to comment.