We have a document available that demonstrates how to create a simple widget. Furthermore, you can reference the source code for the default widgets provided by ThingWorx (e.g. Grid, List, etc.) by navigating to webapps/Thingworx/Common/thingworx/widgets in your file system. Keep in mind, you won't want to modify any of these files, but you can copy them to another location and edit them there to modify an existing widget.