Inline editing for Editor for undefined number and names of columns.

Inline editing for Editor for undefined number and names of columns.

plareszkaplareszka Posts: 12Questions: 5Answers: 2

I have been struggeling for days with this and i am completly stuck.
I need to create a table where names and numbers of columns will depend on 2 parameters. Start and End date. Months columns would have inline editing.

Example for jan2019 & mar2019 we will have Name, Group, Jan19, Feb19, Mar19. If dates would be further appart, we would have more columns.

Is there a way to do something like this with Editor plugin ? I have just purchesed it and i still don't know its full capacity.

I tried designing my tables and code in a 50 different ways, but i can't figure out how to pass generated column names to the view...

Any suggestion would be appriciated.

Answers

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

    Hi,

    There are two components to this - the DataTables aspect, and the Editor aspect.

    For DataTables you want to build an array for the column definitions prior to initialising the table (as DataTables doesn't have the ability to add and remove columns after initialisation). For example:

    var columns = [];
    for ( var i=0 ; i<5 ; i++ ) {
      columns.push( { data: i, name: 'Column index '+i } );
    }
    

    Likewise for Editor you want to do something similar, although with Editor you can use add() to dynamically add fields to the form:

    for ( var i=0 ; i<5 ; i++ ) {
      editor.add( {
        name: i,
        label: 'Field index '+i
      } );
    }
    

    I've used simple for loops there - you would want to use something from your date calculations and use a different data and name properties I would imagine. But that's the basic idea.

    Allan

  • plareszkaplareszka Posts: 12Questions: 5Answers: 2
    edited November 2018

    Thanks @Alan , this helps a bit but i still don't know how to build controller part for this. From what I have seen, controler needs to have exact same model as table structure in db.

    So since i am building my "Months" data mostly as custom object, how can i pass it to Editor ?

    For Example my tables looks like this :

    Valuestable
    Project_ID , Month, Value, RateID
    
    RateTable
    RateID, Grade, Year, Country
    

    And to get my model i group values by
    Groupy and Country

    So as a resault my model looks something like this

    Row1 {
       Grade : 5B
       Country : USA
        Data: {
                  Year : 2018
                  Month: 1
                  Value: 20
                },{
                  Year : 2018
                  Month: 2
                  Value: 15
               },{ etc...
    

    Is it possible to pass this custom model in to Editor ? btw i work with .net mvc

This discussion has been closed.