Can Editor be used with non sql data ?

Can Editor be used with non sql data ?

plareszkaplareszka Posts: 12Questions: 5Answers: 2

In all examples i have seen, editor oprates only on data and models fetched from SQL tables....is it possible to create a custom object and join it with the table data in Editor ?

For example i have a table Users with columns Name, Location, Gender

However i want to expand this model by a new property that dosen't exist in database. For example "Salary" which is calculated inside the controler.

Is there a way to pass such object in to Editor Controller (.net mvc). Or only objects that match db tables can be used ?

This question has an accepted answers - jump to answer

Answers

  • Keith_HKeith_H Posts: 54Questions: 19Answers: 1

    I think i understand your request.

    What I do is to create a datatable.

    Then I will call my routine to read the data I want from the database.

    I will then fill the datatable via the row.add() call.

    When I do this, I can the data from the recordset (converted to json), and optionally add new columns. So below, I have 2 columns from the database and another 2 created as input fields (one checkbox and another hidden field).

    Hope this helps.

            var locTable        = $('#tblTest').DataTable();
            var locIconChk  = '';
            var locHidId        = '';
    
            locTable.clear();
    
            for (var i = 0; i < pData.length; i++) {
                locIconChk  = '<input type="checkbox" name="chkOpsMassRepl" id="chkOpsMassRepl'+i+'" class="JqUiCheckBox" />';
                locHidId        = '<input type="hidden" name="hidOpsMassRepl" id="hidOpsMassRepl'+i+'" value="'+trim(pData[i].PART) + '" />';
    
                locTable.row.add([
                     pData[i].PART
                    ,pData[i].DESC
                    ,locIconChk + locHidId
                ]);
            }
            locTable.draw().columns.adjust();
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @plareszka ,

    It sounds like this example here may do the trick for you. Here, the date field doesn't exist in the database, but is displayed in the table.

    Cheers,

    Colin

  • plareszkaplareszka Posts: 12Questions: 5Answers: 2

    @colin Not sure if that is right....

    Here, the date field doesn't exist in the database, but is displayed in the table.

    But from what i checked in the provided demo sql....table users actually have updated_date column....

    My question is...is it possible to add to the Editor/Datatables table, data outside of the SQL table....For the example you used here

    What if i i wanted to add column "Second Name" and populate it within the controller with "Robert" for each row ?

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin
    Answer ✓

    Yes you can do that if you want. In the controller you would typically have something like:

                var response = new Editor(db, "staff")
                    .Field(new Field("start_date")
                       ...
                    )
                    .Process(request)
                    .Data();
     
                return Json(response);
    

    You can loop over the response.data property and modify its contents as you need. Its an array and each array entry represents a row as read from the DB. That way you can get the extra information for each row using whatever methods you need in the controller.

    The other option, depending on what you want to do exactly, is that you could use columns.render on the client-side. For example if you are performing a calculation, its handy to get the client-side to do it rather than the server.

    Allan

This discussion has been closed.