How to pass the generated value from the table to the editor?

How to pass the generated value from the table to the editor?

imballamaimballama Posts: 12Questions: 5Answers: 0

I count the values in the table like this

 {
              'data': 'calendar',
              'render': function (data,type,row) {
                  let count = 0;
                  if(isNaN(parseInt(data[`${daysInMonth[0]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[1]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[2]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[3]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[4]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[5]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[6]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[7]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[8]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[9]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[10]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[11]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[12]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[13]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[14]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[15]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[16]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[17]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[18]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[19]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[20]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[21]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[22]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[23]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[24]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[25]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[26]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[27]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[28]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[29]}`])) === false){count+=1}
                  if(isNaN(parseInt(data[`${daysInMonth[30]}`])) === false){count+=1}

                  return (
                      count
                  )
              }
          }

How can I pass this value to the editor field?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    When you say pass to an Editor field, do you mean you want to send that value back to the server immediately? Or automatically fill in a value when the editing form loads?

    Colin

  • imballamaimballama Posts: 12Questions: 5Answers: 0
    edited February 2022

    I think automatically fill in a value when the editing form loads

  • allanallan Posts: 63,678Questions: 1Answers: 10,498 Site admin

    I'm not clear on what you would do with it in Editor? If you edited the count, what would happen?

    Also, it might be worth using a three line lor loop there rather than listing every option!

    Allan

  • imballamaimballama Posts: 12Questions: 5Answers: 0

    It is necessary for me that these data counted in the table got to a DB. I don't quite understand how to implement this. When you open the editor, there is no such data in the corresponding fields.

  • imballamaimballama Posts: 12Questions: 5Answers: 0

    Colin , I thought about it and decided that I need to immediately add them to the database. Can you help me with this?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    This is how you can change the values when the form opens : http://live.datatables.net/wivatezi/72/edit

    It would probably be a bad move to do it automatically - as you would be contacting the server for each row of the table on initialisation. This would be horrendously slow even for a small number of records,

    Colin

  • imballamaimballama Posts: 12Questions: 5Answers: 0

    I do not quite understand how to dynamically read the data in this case?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    This here is doing what your code appears to be doing. It's rendering a different value into the salary field than is in the data, then that value is loaded when the record is edited.

    Colin

  • imballamaimballama Posts: 12Questions: 5Answers: 0
    edited February 2022

    Ok, I try this

Sign In or Register to comment.