We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Data Binding Issue

Hi,
I am working on syncfusion scheduler and I tried to bind data in different ways as they are mentioned in documentation.

I have followed the all steps for data binding ,tried my hand with different adaptors, also passed the same  properties as passed by syncfusion apis. But I am still unable to bind data.
 
Using asp.net core for apis and angular 7 with mongodb database.

Thanks
Deepak sharma

3 Replies

NR Nevitha Ravi Syncfusion Team April 15, 2019 12:28 PM UTC

Hi Deepak, 
 
Greetings from Syncfusion Support. 
  
We can bind the data to Scheduler from MongoDB  and we have prepared a sample for your reference which can be downloaded from the following location. 
  
  
In the above sample, we have added CRUD actions code snippet in server.js. 
MongoClient.connect(url, function (err, db) { 
    if (err) throw err; 
    var dbo = db.db("mydb"); 
    app.use(function (req, res, next) { 
        res.header("Access-Control-Allow-Origin", "*"); 
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); 
        next(); 
    }); 
    app.post("/GetData", (req, res) => { 
        dbo.collection('ScheduleData').find({}).toArray((err, cus) => { 
            res.send(cus); 
        }); 
    }); 
    app.post("/BatchData", (req, res) => { 
        console.log(req.body); 
        var eventData = []; 
        if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 0)) { 
            (req.body.action == "insert") ? eventData.push(req.body.value) : eventData = req.body.added; 
            for (var i = 0; i < eventData.length; i++) { 
                var sdate = new Date(eventData[i].StartTime); 
                var edate = new Date(eventData[i].EndTime); 
                eventData[i].StartTime = (new Date(+sdate - (sdate.getTimezoneOffset() * 60000))); 
                eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000))); 
                dbo.collection('ScheduleData').insertOne(eventData[i]); 
            } 
        } 
        if (req.body.action == "update" || (req.body.action == "batch" && req.body.changed.length > 0)) { 
            (req.body.action == "update") ? eventData.push(req.body.value) : eventData = req.body.changed; 
            for (var i = 0; i < eventData.length; i++) { 
                delete eventData[i]._id; 
                var sdate = new Date(eventData[i].StartTime); 
                var edate = new Date(eventData[i].EndTime); 
                eventData[i].StartTime = (new Date(+sdate - (sdate.getTimezoneOffset() * 60000))); 
                eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000))); 
                dbo.collection('ScheduleData').updateOne({ "Id": eventData[i].Id }, { $set: eventData[i] }); 
            } 
        } 
        if (req.body.action == "remove" || (req.body.action == "batch" && req.body.deleted.length > 0)) { 
            (req.body.action == "remove") ? eventData.push({ Id: req.body.key }) : eventData = req.body.deleted; 
            for (var i = 0; i < eventData.length; i++) { 
                dbo.collection('ScheduleData').deleteOne({ "Id": eventData[i].Id }); 
            } 
        } 
        res.send(req.body); 
    }); 
}); 
 
 
Note: We have removed the local offset time before inserting and updating the events in the database collection to render the appointments without considering system UTC in the scheduler. 
  
In the below code we have given the GetData and BatchData url path to initial fetching and for performing CRUD actions using UrlAdaptor and assigned it to the scheduler datasource. 
    private dataManager: DataManager = new DataManager({ 
    url: 'http://localhost:5000/GetData', 
    crudUrl: 'http://localhost:5000/BatchData', 
    adaptor: new UrlAdaptor, 
    crossDomain: true 
  }); 
  public eventSettings: EventSettingsModel = { dataSource: this.dataManager }; 
 
Steps to run the sample: 
  1. Run MongoDB and create the collection named ‘ScheduleData’ in ‘mydb’ database.
  2. Run the below comments.
npm install 
npm run server 
npm start 
  
Please try the above sample and let us know if you need further assistance. 
  
Regards, 
Nevitha. 



YL Youssef Lakdime November 5, 2019 09:27 PM UTC

Hi Navitha,

Whenever I save an appointment, right now only the startTime and the endTime are being sent to the Database. How can I make sure that also the other fields are being submitted, like subject / description / some custom fields that I made, like 'relative'.

I have modified the above function a bit , but the subject and description are still not being sent to the DB. Can you help me out?

Thanks in advance

this is my code:


app.post("/BatchData", (req, res) => {
console.log(req.body);
var eventData = [];
if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 0)) {
(req.body.action == "insert") ? eventData.push(req.body.value) : eventData = req.body.added;
for (var i = 0; i < eventData.length; i++) {
var sdate = new Date(eventData[i].StartTime);
var edate = new Date(eventData[i].EndTime);
eventData[i].Subject = eventData[i].Subject;
eventData[i].Description = eventData[i].Description;
eventData[i].StartTime = (new Date(+sdate - (sdate.getTimezoneOffset() * 60000)));
eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000)));
//how can I add the other fields here;
        }
}



VD Vinitha Devi Murugan Syncfusion Team November 7, 2019 11:46 AM UTC

Hi Deepak, 
 
Thanks for you update. 
 
We have checked the reported case with our previously provided sample but all fields are properly send to the database at our end and for the same we have prepared the video demo for your reference with below sample. 
 
 
Screenshot:  
 
 
Kindly try the sample and if still issue persists, try to reproduce the issue in the above sample to proceed further. 
 
Regards, 
M.Vinitha devi    
 


Loader.
Live Chat Icon For mobile
Up arrow icon