Sharukh k shaji
Sharukh k shaji

Reputation: 134

How to create dynamic columns in jqxGrid jquery

I have a jqxGrid and I need to populate it with some object. The object is completely random that some data fields may be empty. I need to show a particular coloumn only if that data is present in that object.


columns: [
              { text: 'Application Id', filtertype: 'input', datafield: 'ApplicationId', cellsrenderer: AppIdRenderer, width: appId },
              { text: 'Name', columntype: 'textbox', filtertype: 'input', datafield: 'ApplicantName', width: Applicant },
              { text: 'Submitted Date', datafield: 'SubmitDate', filtertype: 'date', cellsalign: 'left', cellsformat: 'dd/MM/yyyy', width: ApplDate },
              { text: 'Last Action', datafield: 'LastActionDate', filtertype: 'date', cellsalign: 'left', cellsformat: 'dd/MM/yyyy', width: ApplDate },
              { text: 'University', columntype: 'textbox', filtertype: 'checkedlist', datafield: 'AppType', width: UTYApplied },
              { text: 'Course Applied', columntype: 'textbox', filtertype: 'checkedlist', datafield: 'AppliedCourse', width: ApplCourse },
              { text: 'Latest Comments', columntype: 'textbox', filtertype: 'input', datafield: 'LatestComments', width: ApplCourse },
              { text: 'AppStatus', datafield: 'AppStatus' },
              { text: 'Status', columntype: 'textbox', filtertype: 'checkedlist', datafield: 'Status', width: ApplCourse }
]

for eg: I need to show the coloumn "LatestComments" only if the datafield "LatestComments" occurs.

Upvotes: 3

Views: 978

Answers (1)

badera
badera

Reputation: 1545

You write very little about how you use the jqxGrid (local data source, remote data source) etc. This may be essential in proposing a solution.

If I understand your question correctly, you either want to hide or show a whole column according whether in every row a certain datafield is either fully undefined or at least particularly populated with data.

For this, you need to process your data and check for such situation (loop through every row, check if at least once a datafield contains data). Then, in the bindingcomplete callback, loop through every column and apply either showcolumn or hidecolumn.

Upvotes: 2

Related Questions